| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "chrome/app/chrome_command_ids.h" | 7 #include "chrome/app/chrome_command_ids.h" |
| 8 #include "chrome/browser/content_settings/cookie_settings_factory.h" | 8 #include "chrome/browser/content_settings/cookie_settings_factory.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/tab_dialogs.h" | 10 #include "chrome/browser/ui/tab_dialogs.h" |
| 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 12 #include "chrome/browser/ui/test/test_browser_dialog.h" |
| 12 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.h" |
| 13 #include "chrome/test/base/in_process_browser_test.h" | 14 #include "chrome/test/base/in_process_browser_test.h" |
| 14 #include "chrome/test/base/ui_test_utils.h" | 15 #include "chrome/test/base/ui_test_utils.h" |
| 15 #include "components/content_settings/core/browser/cookie_settings.h" | 16 #include "components/content_settings/core/browser/cookie_settings.h" |
| 16 #include "net/test/embedded_test_server/embedded_test_server.h" | 17 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 17 | 18 |
| 18 typedef InProcessBrowserTest CollectedCookiesTest; | 19 class CollectedCookiesTest : public DialogBrowserTest { |
| 20 public: |
| 21 CollectedCookiesTest() {} |
| 22 |
| 23 // TestDialogInterface: |
| 24 void ShowDialog(int index) override { |
| 25 ASSERT_TRUE(embedded_test_server()->Start()); |
| 26 |
| 27 // Disable cookies. |
| 28 CookieSettingsFactory::GetForProfile(browser()->profile()) |
| 29 ->SetDefaultCookieSetting(CONTENT_SETTING_BLOCK); |
| 30 |
| 31 // Load a page with cookies. |
| 32 ui_test_utils::NavigateToURL( |
| 33 browser(), embedded_test_server()->GetURL("/cookie1.html")); |
| 34 |
| 35 content::WebContents* web_contents = |
| 36 browser()->tab_strip_model()->GetActiveWebContents(); |
| 37 TabDialogs::FromWebContents(web_contents)->ShowCollectedCookies(); |
| 38 } |
| 39 |
| 40 private: |
| 41 DISALLOW_COPY_AND_ASSIGN(CollectedCookiesTest); |
| 42 }; |
| 43 |
| 44 TEST_BROWSER_DIALOG(CollectedCookiesTest); |
| 19 | 45 |
| 20 // If this crashes on Windows, use http://crbug.com/79331 | 46 // If this crashes on Windows, use http://crbug.com/79331 |
| 21 IN_PROC_BROWSER_TEST_F(CollectedCookiesTest, DoubleDisplay) { | 47 IN_PROC_BROWSER_TEST_F(CollectedCookiesTest, DoubleDisplay) { |
| 22 ASSERT_TRUE(embedded_test_server()->Start()); | 48 ShowDialog(0); |
| 23 | 49 |
| 24 // Disable cookies. | 50 // Click on the info link a second time. |
| 25 CookieSettingsFactory::GetForProfile(browser()->profile()) | |
| 26 ->SetDefaultCookieSetting(CONTENT_SETTING_BLOCK); | |
| 27 | |
| 28 // Load a page with cookies. | |
| 29 ui_test_utils::NavigateToURL( | |
| 30 browser(), embedded_test_server()->GetURL("/cookie1.html")); | |
| 31 | |
| 32 // Click on the info link twice. | |
| 33 content::WebContents* web_contents = | 51 content::WebContents* web_contents = |
| 34 browser()->tab_strip_model()->GetActiveWebContents(); | 52 browser()->tab_strip_model()->GetActiveWebContents(); |
| 35 TabDialogs::FromWebContents(web_contents)->ShowCollectedCookies(); | 53 TabDialogs::FromWebContents(web_contents)->ShowCollectedCookies(); |
| 36 TabDialogs::FromWebContents(web_contents)->ShowCollectedCookies(); | |
| 37 } | 54 } |
| 38 | 55 |
| 39 // If this crashes on Windows, use http://crbug.com/79331 | 56 // If this crashes on Windows, use http://crbug.com/79331 |
| 40 IN_PROC_BROWSER_TEST_F(CollectedCookiesTest, NavigateAway) { | 57 IN_PROC_BROWSER_TEST_F(CollectedCookiesTest, NavigateAway) { |
| 41 ASSERT_TRUE(embedded_test_server()->Start()); | 58 ShowDialog(0); |
| 42 | |
| 43 // Disable cookies. | |
| 44 CookieSettingsFactory::GetForProfile(browser()->profile()) | |
| 45 ->SetDefaultCookieSetting(CONTENT_SETTING_BLOCK); | |
| 46 | |
| 47 // Load a page with cookies. | |
| 48 ui_test_utils::NavigateToURL( | |
| 49 browser(), embedded_test_server()->GetURL("/cookie1.html")); | |
| 50 | |
| 51 // Click on the info link. | |
| 52 content::WebContents* web_contents = | |
| 53 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 54 TabDialogs::FromWebContents(web_contents)->ShowCollectedCookies(); | |
| 55 | 59 |
| 56 // Navigate to another page. | 60 // Navigate to another page. |
| 57 ui_test_utils::NavigateToURL( | 61 ui_test_utils::NavigateToURL( |
| 58 browser(), embedded_test_server()->GetURL("/cookie2.html")); | 62 browser(), embedded_test_server()->GetURL("/cookie2.html")); |
| 59 } | 63 } |
| OLD | NEW |