Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Side by Side Diff: chrome/browser/banners/app_banner_data_fetcher_browsertest.cc

Issue 1017883002: [App banners] Add browser test for canceling banners (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Renaming variable Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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 "chrome/browser/banners/app_banner_data_fetcher.h" 5 #include "chrome/browser/banners/app_banner_data_fetcher.h"
6 6
7 #include "base/command_line.h"
7 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
8 #include "base/run_loop.h" 9 #include "base/run_loop.h"
9 #include "base/task_runner.h" 10 #include "base/task_runner.h"
10 #include "chrome/browser/ui/browser.h" 11 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" 12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
12 #include "chrome/test/base/in_process_browser_test.h" 13 #include "chrome/test/base/in_process_browser_test.h"
13 #include "chrome/test/base/ui_test_utils.h" 14 #include "chrome/test/base/ui_test_utils.h"
15 #include "content/public/common/content_switches.h"
14 #include "content/public/test/test_navigation_observer.h" 16 #include "content/public/test/test_navigation_observer.h"
15 #include "net/test/embedded_test_server/embedded_test_server.h" 17 #include "net/test/embedded_test_server/embedded_test_server.h"
16 18
17 namespace banners { 19 namespace banners {
18 20
19 class TestObserver : public AppBannerDataFetcher::Observer { 21 class TestObserver : public AppBannerDataFetcher::Observer {
20 public: 22 public:
21 TestObserver(AppBannerDataFetcher* fetcher, base::Closure quit_closure) 23 TestObserver(AppBannerDataFetcher* fetcher, base::Closure quit_closure)
22 : fetcher_(fetcher), 24 : fetcher_(fetcher),
23 quit_closure_(quit_closure) { 25 quit_closure_(quit_closure) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 62 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
61 InProcessBrowserTest::SetUpOnMainThread(); 63 InProcessBrowserTest::SetUpOnMainThread();
62 } 64 }
63 65
64 bool OnInvalidManifest(AppBannerDataFetcher* fetcher) override { 66 bool OnInvalidManifest(AppBannerDataFetcher* fetcher) override {
65 base::MessageLoop::current()->PostTask(FROM_HERE, quit_closure_); 67 base::MessageLoop::current()->PostTask(FROM_HERE, quit_closure_);
66 manifest_was_invalid_ = true; 68 manifest_was_invalid_ = true;
67 return false; 69 return false;
68 } 70 }
69 71
72 void SetUpCommandLine(base::CommandLine* command_line) override {
73 command_line->AppendSwitch(
74 switches::kEnableExperimentalWebPlatformFeatures);
75 }
76
70 protected: 77 protected:
71 void RunFetcher(const GURL& url, 78 void RunFetcher(const GURL& url,
72 bool expected_manifest_valid, 79 bool expected_manifest_valid,
73 bool expected_outcome) { 80 bool expected_to_show) {
74 content::WebContents* web_contents = 81 content::WebContents* web_contents =
75 browser()->tab_strip_model()->GetActiveWebContents(); 82 browser()->tab_strip_model()->GetActiveWebContents();
76 scoped_refptr<AppBannerDataFetcher> fetcher( 83 scoped_refptr<AppBannerDataFetcher> fetcher(
77 new AppBannerDataFetcher(web_contents, weak_factory_.GetWeakPtr(), 84 new AppBannerDataFetcher(web_contents, weak_factory_.GetWeakPtr(),
78 128)); 85 128));
79 86
80 base::RunLoop run_loop; 87 base::RunLoop run_loop;
81 quit_closure_ = run_loop.QuitClosure(); 88 quit_closure_ = run_loop.QuitClosure();
82 scoped_ptr<TestObserver> observer(new TestObserver(fetcher.get(), 89 scoped_ptr<TestObserver> observer(new TestObserver(fetcher.get(),
83 run_loop.QuitClosure())); 90 run_loop.QuitClosure()));
84 fetcher->Start(url); 91 fetcher->Start(url);
85 run_loop.Run(); 92 run_loop.Run();
86 93
87 EXPECT_EQ(expected_manifest_valid, !manifest_was_invalid_); 94 EXPECT_EQ(expected_manifest_valid, !manifest_was_invalid_);
88 EXPECT_EQ(expected_outcome, observer->will_show()); 95 EXPECT_EQ(expected_to_show, observer->will_show());
89 ASSERT_FALSE(fetcher->is_active()); 96 ASSERT_FALSE(fetcher->is_active());
90 } 97 }
91 98
92 void LoadURLAndWaitForServiceWorker(const GURL& url) { 99 void LoadURLAndWaitForServiceWorker(const GURL& url) {
93 content::WebContents* web_contents = 100 content::WebContents* web_contents =
94 browser()->tab_strip_model()->GetActiveWebContents(); 101 browser()->tab_strip_model()->GetActiveWebContents();
95 content::TestNavigationObserver observer(web_contents, 2); 102 content::TestNavigationObserver observer(web_contents, 2);
96 ui_test_utils::NavigateToURL(browser(), url); 103 ui_test_utils::NavigateToURL(browser(), url);
97 observer.Wait(); 104 observer.Wait();
98 EXPECT_EQ("sw_activated", observer.last_navigation_url().ref()); 105 EXPECT_EQ("sw_activated", observer.last_navigation_url().ref());
(...skipping 28 matching lines...) Expand all
127 134
128 LoadURLAndWaitForServiceWorker(test_url); 135 LoadURLAndWaitForServiceWorker(test_url);
129 RunFetcher(web_contents->GetURL(), false, false); 136 RunFetcher(web_contents->GetURL(), false, false);
130 137
131 // Advance by a day, then visit the page again. Still shouldn't see a banner. 138 // Advance by a day, then visit the page again. Still shouldn't see a banner.
132 AppBannerDataFetcher::SetTimeDeltaForTesting(1); 139 AppBannerDataFetcher::SetTimeDeltaForTesting(1);
133 LoadURLAndWaitForServiceWorker(test_url); 140 LoadURLAndWaitForServiceWorker(test_url);
134 RunFetcher(web_contents->GetURL(), false, false); 141 RunFetcher(web_contents->GetURL(), false, false);
135 } 142 }
136 143
144 IN_PROC_BROWSER_TEST_F(AppBannerDataFetcherBrowserTest, CancelBanner) {
145 std::string valid_page = "/banners/cancel_test_page.html";
146 GURL test_url = embedded_test_server()->GetURL(valid_page);
147 content::WebContents* web_contents =
148 browser()->tab_strip_model()->GetActiveWebContents();
149
150 LoadURLAndWaitForServiceWorker(test_url);
151 RunFetcher(web_contents->GetURL(), true, false);
152
153 // Advance by a day, then visit the page again. Still shouldn't see a banner.
154 AppBannerDataFetcher::SetTimeDeltaForTesting(1);
155 LoadURLAndWaitForServiceWorker(test_url);
156 RunFetcher(web_contents->GetURL(), true, false);
157 }
158
137 } // namespace banners 159 } // namespace banners
OLDNEW
« no previous file with comments | « chrome/browser/banners/app_banner_data_fetcher.cc ('k') | chrome/test/data/banners/cancel_test_page.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698