tapted | 3888fbf | 2017-01-12 02:55:21 | [diff] [blame] | 1 | // 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 Kasting | 919ce65 | 2020-05-07 10:22:36 | [diff] [blame^] | 18 | #include "content/public/test/browser_test.h" |
tapted | 3888fbf | 2017-01-12 02:55:21 | [diff] [blame] | 19 | #include "net/test/embedded_test_server/embedded_test_server.h" |
tapted | 3888fbf | 2017-01-12 02:55:21 | [diff] [blame] | 20 | |
| 21 | class CollectedCookiesTest : public DialogBrowserTest { |
| 22 | public: |
| 23 | CollectedCookiesTest() {} |
| 24 | |
tapted | 3d35b33 | 2017-02-10 00:17:22 | [diff] [blame] | 25 | // DialogBrowserTest: |
Peter Kasting | cf49b7b79 | 2017-12-18 23:27:45 | [diff] [blame] | 26 | void ShowUi(const std::string& name) override { |
Ahmed Fakhry | 2f87779 | 2018-10-10 19:34:49 | [diff] [blame] | 27 | // Web modal dialogs' bounds may exceed the display's work area. |
| 28 | // https://crbug.com/893292. |
| 29 | set_should_verify_dialog_bounds(false); |
| 30 | |
tapted | 3888fbf | 2017-01-12 02:55:21 | [diff] [blame] | 31 | 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 Kasting | cf49b7b79 | 2017-12-18 23:27:45 | [diff] [blame] | 50 | // Test that calls ShowUi("default"). |
Bret Sepulveda | 8d73ce2 | 2018-07-31 18:35:19 | [diff] [blame] | 51 | IN_PROC_BROWSER_TEST_F(CollectedCookiesTest, InvokeUi_default) { |
Peter Kasting | cf49b7b79 | 2017-12-18 23:27:45 | [diff] [blame] | 52 | ShowAndVerifyUi(); |
tapted | 3888fbf | 2017-01-12 02:55:21 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | // If this crashes on Windows, use http://crbug.com/79331 |
| 56 | IN_PROC_BROWSER_TEST_F(CollectedCookiesTest, DoubleDisplay) { |
Peter Kasting | cf49b7b79 | 2017-12-18 23:27:45 | [diff] [blame] | 57 | ShowUi(std::string()); |
tapted | 3888fbf | 2017-01-12 02:55:21 | [diff] [blame] | 58 | |
| 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 |
| 66 | IN_PROC_BROWSER_TEST_F(CollectedCookiesTest, NavigateAway) { |
Peter Kasting | cf49b7b79 | 2017-12-18 23:27:45 | [diff] [blame] | 67 | ShowUi(std::string()); |
tapted | 3888fbf | 2017-01-12 02:55:21 | [diff] [blame] | 68 | |
| 69 | // Navigate to another page. |
Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 70 | ui_test_utils::NavigateToURL(browser(), |
| 71 | embedded_test_server()->GetURL("/cookie2.html")); |
tapted | 3888fbf | 2017-01-12 02:55:21 | [diff] [blame] | 72 | } |