blob: 3dbf63c83c0e65d3c615fee187fc88981544015f [file] [log] [blame]
tapted3888fbf2017-01-12 02:55:211// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// 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:
23 CollectedCookiesTest() {}
24
tapted3d35b332017-02-10 00:17:2225 // DialogBrowserTest:
Peter Kastingcf49b7b792017-12-18 23:27:4526 void ShowUi(const std::string& name) override {
Ahmed Fakhry2f877792018-10-10 19:34:4927 // Web modal dialogs' bounds may exceed the display's work area.
28 // https://crbug.com/893292.
29 set_should_verify_dialog_bounds(false);
30
tapted3888fbf2017-01-12 02:55:2131 ASSERT_TRUE(embedded_test_server()->Start());
32
33 // Disable cookies.
34 CookieSettingsFactory::GetForProfile(browser()->profile())
35 ->SetDefaultCookieSetting(CONTENT_SETTING_BLOCK);
36
37 // Load a page with cookies.
38 ui_test_utils::NavigateToURL(
39 browser(), embedded_test_server()->GetURL("/cookie1.html"));
40
41 content::WebContents* web_contents =
42 browser()->tab_strip_model()->GetActiveWebContents();
43 TabDialogs::FromWebContents(web_contents)->ShowCollectedCookies();
44 }
45
46 private:
47 DISALLOW_COPY_AND_ASSIGN(CollectedCookiesTest);
48};
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.
Aran Gilmand217b5b2019-04-11 17:45:4370 ui_test_utils::NavigateToURL(browser(),
71 embedded_test_server()->GetURL("/cookie2.html"));
tapted3888fbf2017-01-12 02:55:2172}