Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / views / collected_cookies_views_browsertest.cc
blob7e021930279954cee1c26e5ccab5d9eceb3abeb4
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.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 "net/test/embedded_test_server/embedded_test_server.h"
14 class CollectedCookiesViewsTest : public InProcessBrowserTest {
15 public:
16 void SetUpOnMainThread() override {
17 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
19 // Disable cookies.
20 CookieSettings::Factory::GetForProfile(browser()->profile())
21 ->SetDefaultCookieSetting(CONTENT_SETTING_BLOCK);
23 // Load a page with cookies.
24 ui_test_utils::NavigateToURL(
25 browser(), embedded_test_server()->GetURL("/cookie1.html"));
27 // Spawn a cookies dialog. Note that |cookies_dialog_| will delete itself
28 // automatically when it closes.
29 cookies_dialog_ = new CollectedCookiesViews(
30 browser()->tab_strip_model()->GetActiveWebContents());
33 // Closing dialog with modified data will shows infobar.
34 void SetDialogChanged() { cookies_dialog_->status_changed_ = true; }
36 void CloseCookiesDialog() { cookies_dialog_->Close(); }
38 size_t infobar_count() const {
39 content::WebContents* web_contents =
40 browser()->tab_strip_model()->GetActiveWebContents();
41 return web_contents ?
42 InfoBarService::FromWebContents(web_contents)->infobar_count() : 0;
45 private:
46 CollectedCookiesViews* cookies_dialog_ = nullptr;
49 IN_PROC_BROWSER_TEST_F(CollectedCookiesViewsTest, CloseDialog) {
50 // Test closing dialog without changing data.
51 CloseCookiesDialog();
52 EXPECT_EQ(0u, infobar_count());
55 IN_PROC_BROWSER_TEST_F(CollectedCookiesViewsTest, ChangeAndCloseDialog) {
56 // Test closing dialog with changing data. Dialog will show infobar.
57 SetDialogChanged();
58 CloseCookiesDialog();
59 EXPECT_EQ(1u, infobar_count());
62 IN_PROC_BROWSER_TEST_F(CollectedCookiesViewsTest, ChangeAndNavigateAway) {
63 // Test navigation after changing dialog data. Changed dialog should not show
64 // infobar or crash because InfoBarService is gone.
66 SetDialogChanged();
68 // Navigation in the owning tab will close dialog.
69 ui_test_utils::NavigateToURL(browser(),
70 embedded_test_server()->GetURL("/cookie2.html"));
72 EXPECT_EQ(0u, infobar_count());
75 IN_PROC_BROWSER_TEST_F(CollectedCookiesViewsTest, ChangeAndCloseTab) {
76 // Test closing tab after changing dialog data. Changed dialog should not
77 // show infobar or crash because InfoBarService is gone.
79 SetDialogChanged();
81 // Closing the owning tab will close dialog.
82 browser()->tab_strip_model()->GetActiveWebContents()->Close();
84 EXPECT_EQ(0u, infobar_count());