Infobar material design refresh: layout
[chromium-blink-merge.git] / chrome / browser / ui / views / collected_cookies_views_browsertest.cc
blob5ae8780f5459d2da312ea27ed4c378cc12cf87dc
1 // Copyright 2015 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 #include "chrome/browser/content_settings/cookie_settings_factory.h"
6 #include "chrome/browser/infobars/infobar_service.h"
7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/tabs/tab_strip_model.h"
9 #include "chrome/browser/ui/views/collected_cookies_views.h"
10 #include "chrome/test/base/in_process_browser_test.h"
11 #include "chrome/test/base/ui_test_utils.h"
12 #include "components/content_settings/core/browser/cookie_settings.h"
13 #include "net/test/embedded_test_server/embedded_test_server.h"
15 class CollectedCookiesViewsTest : public InProcessBrowserTest {
16 public:
17 void SetUpOnMainThread() override {
18 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
20 // Disable cookies.
21 CookieSettingsFactory::GetForProfile(browser()->profile())
22 ->SetDefaultCookieSetting(CONTENT_SETTING_BLOCK);
24 // Load a page with cookies.
25 ui_test_utils::NavigateToURL(
26 browser(), embedded_test_server()->GetURL("/cookie1.html"));
28 // Spawn a cookies dialog. Note that |cookies_dialog_| will delete itself
29 // automatically when it closes.
30 cookies_dialog_ = new CollectedCookiesViews(
31 browser()->tab_strip_model()->GetActiveWebContents());
34 // Closing dialog with modified data will shows infobar.
35 void SetDialogChanged() { cookies_dialog_->status_changed_ = true; }
37 void CloseCookiesDialog() { cookies_dialog_->Close(); }
39 size_t infobar_count() const {
40 content::WebContents* web_contents =
41 browser()->tab_strip_model()->GetActiveWebContents();
42 return web_contents ?
43 InfoBarService::FromWebContents(web_contents)->infobar_count() : 0;
46 private:
47 CollectedCookiesViews* cookies_dialog_ = nullptr;
50 IN_PROC_BROWSER_TEST_F(CollectedCookiesViewsTest, CloseDialog) {
51 // Test closing dialog without changing data.
52 CloseCookiesDialog();
53 EXPECT_EQ(0u, infobar_count());
56 IN_PROC_BROWSER_TEST_F(CollectedCookiesViewsTest, ChangeAndCloseDialog) {
57 // Test closing dialog with changing data. Dialog will show infobar.
58 SetDialogChanged();
59 CloseCookiesDialog();
60 EXPECT_EQ(1u, infobar_count());
63 IN_PROC_BROWSER_TEST_F(CollectedCookiesViewsTest, ChangeAndNavigateAway) {
64 // Test navigation after changing dialog data. Changed dialog should not show
65 // infobar or crash because InfoBarService is gone.
67 SetDialogChanged();
69 // Navigation in the owning tab will close dialog.
70 ui_test_utils::NavigateToURL(browser(),
71 embedded_test_server()->GetURL("/cookie2.html"));
73 EXPECT_EQ(0u, infobar_count());
76 IN_PROC_BROWSER_TEST_F(CollectedCookiesViewsTest, ChangeAndCloseTab) {
77 // Test closing tab after changing dialog data. Changed dialog should not
78 // show infobar or crash because InfoBarService is gone.
80 SetDialogChanged();
82 // Closing the owning tab will close dialog.
83 browser()->tab_strip_model()->GetActiveWebContents()->Close();
85 EXPECT_EQ(0u, infobar_count());