Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / content_settings / collected_cookies_mac_browsertest.mm
blob9448bf7178d932190971318788a33a0fc69a547f
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.
5 #import "chrome/browser/ui/cocoa/content_settings/collected_cookies_mac.h"
7 #include "chrome/browser/infobars/infobar_service.h"
8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/tabs/tab_strip_model.h"
10 #include "chrome/test/base/in_process_browser_test.h"
11 #include "components/web_modal/web_contents_modal_dialog_manager.h"
12 #include "content/public/test/test_utils.h"
14 using web_modal::WebContentsModalDialogManager;
16 class CollectedCookiesMacTest : public InProcessBrowserTest {
17  public:
18   void SetUpOnMainThread() override {
19     // Spawn a cookies dialog.  Note that |cookies_dialog_| will delete itself
20     // automatically when it closes.
21     cookies_dialog_ = new CollectedCookiesMac(
22         browser()->tab_strip_model()->GetActiveWebContents());
24     content::WebContents* web_contents =
25         browser()->tab_strip_model()->GetActiveWebContents();
26     WebContentsModalDialogManager* web_contents_modal_dialog_manager =
27         WebContentsModalDialogManager::FromWebContents(web_contents);
28     EXPECT_TRUE(web_contents_modal_dialog_manager->IsDialogActive());
29   }
31   // Shows infobar when dialog is closes.
32   void SetDialogChanged() {
33     [cookies_dialog_->sheet_controller() blockOrigin:nullptr];
34   }
36   void CloseCookiesDialog() {
37     cookies_dialog_->PerformClose();
38     content::RunAllPendingInMessageLoop();
39     content::WebContents* web_contents =
40         browser()->tab_strip_model()->GetActiveWebContents();
41     WebContentsModalDialogManager* web_contents_modal_dialog_manager =
42         WebContentsModalDialogManager::FromWebContents(web_contents);
43     EXPECT_FALSE(web_contents_modal_dialog_manager->IsDialogActive());
44   }
46   size_t infobar_count() const {
47     content::WebContents* web_contents =
48         browser()->tab_strip_model()->GetActiveWebContents();
49     return web_contents ?
50         InfoBarService::FromWebContents(web_contents)->infobar_count() : 0;
51   }
53   CollectedCookiesWindowController* sheet_controller() {
54     return cookies_dialog_->sheet_controller();
55   }
57  private:
58   CollectedCookiesMac* cookies_dialog_ = nullptr;
61 // Tests closing dialog without changing data.
62 IN_PROC_BROWSER_TEST_F(CollectedCookiesMacTest, Close) {
63   CloseCookiesDialog();
64   EXPECT_EQ(0u, infobar_count());
67 // Tests closing dialog with changing data. Dialog will show infobar.
68 // TODO(vitalybuka): Fix and re-enable http://crbug.com/450295
69 IN_PROC_BROWSER_TEST_F(CollectedCookiesMacTest, DISABLED_ChangeAndClose) {
70   SetDialogChanged();
71   CloseCookiesDialog();
72   EXPECT_EQ(1u, infobar_count());
75 // Tests closing tab after changing dialog data. Changed dialog should not
76 // show infobar or crash because InfoBarService is gone.
77 // TODO(vitalybuka): Fix and re-enable http://crbug.com/450295
78 IN_PROC_BROWSER_TEST_F(CollectedCookiesMacTest, DISABLED_ChangeAndCloseTab) {
79   SetDialogChanged();
81   // Closing the owning tab will close dialog.
82   browser()->tab_strip_model()->GetActiveWebContents()->Close();
84   content::RunAllPendingInMessageLoop();
85   EXPECT_EQ(0u, infobar_count());
88 IN_PROC_BROWSER_TEST_F(CollectedCookiesMacTest, Outlets) {
89   EXPECT_TRUE([sheet_controller() allowedTreeController]);
90   EXPECT_TRUE([sheet_controller() blockedTreeController]);
91   EXPECT_TRUE([sheet_controller() allowedOutlineView]);
92   EXPECT_TRUE([sheet_controller() blockedOutlineView]);
93   EXPECT_TRUE([sheet_controller() infoBar]);
94   EXPECT_TRUE([sheet_controller() infoBarIcon]);
95   EXPECT_TRUE([sheet_controller() infoBarText]);
96   EXPECT_TRUE([sheet_controller() tabView]);
97   EXPECT_TRUE([sheet_controller() blockedScrollView]);
98   EXPECT_TRUE([sheet_controller() blockedCookiesText]);
99   EXPECT_TRUE([sheet_controller() cookieDetailsViewPlaceholder]);
101   [sheet_controller() closeSheet:nil];
102   content::RunAllPendingInMessageLoop();