Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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_outcome) { |
|
mlamouri (slow - plz ping)
2015/03/17 21:17:20
I know you didn't add that here but it's really co
gone
2015/03/17 21:24:11
When I first wrote this part of the test, there wa
| |
| 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())); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 |
| OLD | NEW |