blob: 3ca0b56eafedda29b9df3189ecb3c92dc1c41fcd [file] [log] [blame]
Avi Drissman4a8573c2022-09-09 19:35:541// Copyright 2012 The Chromium Authors
tapted3888fbf2017-01-12 02:55:212// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <string>
6
7#include "base/command_line.h"
8#include "chrome/app/chrome_command_ids.h"
9#include "chrome/browser/content_settings/cookie_settings_factory.h"
10#include "chrome/browser/ui/browser.h"
11#include "chrome/browser/ui/tab_dialogs.h"
12#include "chrome/browser/ui/tabs/tab_strip_model.h"
13#include "chrome/browser/ui/test/test_browser_dialog.h"
14#include "chrome/common/url_constants.h"
15#include "chrome/test/base/in_process_browser_test.h"
16#include "chrome/test/base/ui_test_utils.h"
17#include "components/content_settings/core/browser/cookie_settings.h"
Peter Kasting919ce652020-05-07 10:22:3618#include "content/public/test/browser_test.h"
tapted3888fbf2017-01-12 02:55:2119#include "net/test/embedded_test_server/embedded_test_server.h"
tapted3888fbf2017-01-12 02:55:2120
21class CollectedCookiesTest : public DialogBrowserTest {
22 public:
Sorin Jianu76486952024-11-28 04:21:5023 CollectedCookiesTest() = default;
tapted3888fbf2017-01-12 02:55:2124
Peter Boströmc75681ac2021-09-24 16:58:4125 CollectedCookiesTest(const CollectedCookiesTest&) = delete;
26 CollectedCookiesTest& operator=(const CollectedCookiesTest&) = delete;
27
tapted3d35b332017-02-10 00:17:2228 // DialogBrowserTest:
Peter Kastingcf49b7b792017-12-18 23:27:4529 void ShowUi(const std::string& name) override {
Ahmed Fakhry2f877792018-10-10 19:34:4930 // Web modal dialogs' bounds may exceed the display's work area.
31 // https://crbug.com/893292.
32 set_should_verify_dialog_bounds(false);
33
tapted3888fbf2017-01-12 02:55:2134 ASSERT_TRUE(embedded_test_server()->Start());
35
36 // Disable cookies.
37 CookieSettingsFactory::GetForProfile(browser()->profile())
38 ->SetDefaultCookieSetting(CONTENT_SETTING_BLOCK);
39
40 // Load a page with cookies.
Lukasz Anforowiczb78290c2021-09-08 04:31:3841 ASSERT_TRUE(ui_test_utils::NavigateToURL(
42 browser(), embedded_test_server()->GetURL("/cookie1.html")));
tapted3888fbf2017-01-12 02:55:2143
44 content::WebContents* web_contents =
45 browser()->tab_strip_model()->GetActiveWebContents();
46 TabDialogs::FromWebContents(web_contents)->ShowCollectedCookies();
47 }
tapted3888fbf2017-01-12 02:55:2148};
49
Peter Kastingcf49b7b792017-12-18 23:27:4550// Test that calls ShowUi("default").
Bret Sepulveda8d73ce22018-07-31 18:35:1951IN_PROC_BROWSER_TEST_F(CollectedCookiesTest, InvokeUi_default) {
Peter Kastingcf49b7b792017-12-18 23:27:4552 ShowAndVerifyUi();
tapted3888fbf2017-01-12 02:55:2153}
54
55// If this crashes on Windows, use http://crbug.com/79331
56IN_PROC_BROWSER_TEST_F(CollectedCookiesTest, DoubleDisplay) {
Peter Kastingcf49b7b792017-12-18 23:27:4557 ShowUi(std::string());
tapted3888fbf2017-01-12 02:55:2158
59 // Click on the info link a second time.
60 content::WebContents* web_contents =
61 browser()->tab_strip_model()->GetActiveWebContents();
62 TabDialogs::FromWebContents(web_contents)->ShowCollectedCookies();
63}
64
65// If this crashes on Windows, use http://crbug.com/79331
66IN_PROC_BROWSER_TEST_F(CollectedCookiesTest, NavigateAway) {
Peter Kastingcf49b7b792017-12-18 23:27:4567 ShowUi(std::string());
tapted3888fbf2017-01-12 02:55:2168
69 // Navigate to another page.
Lukasz Anforowiczb78290c2021-09-08 04:31:3870 ASSERT_TRUE(ui_test_utils::NavigateToURL(
71 browser(), embedded_test_server()->GetURL("/cookie2.html")));
tapted3888fbf2017-01-12 02:55:2172}