| 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/command_line.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/location.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/single_thread_task_runner.h" |
| 10 #include "base/task_runner.h" | 11 #include "base/task_runner.h" |
| 12 #include "base/thread_task_runner_handle.h" |
| 11 #include "chrome/browser/banners/app_banner_data_fetcher_desktop.h" | 13 #include "chrome/browser/banners/app_banner_data_fetcher_desktop.h" |
| 12 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 14 #include "chrome/test/base/in_process_browser_test.h" | 16 #include "chrome/test/base/in_process_browser_test.h" |
| 15 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
| 16 #include "content/public/common/content_switches.h" | 18 #include "content/public/common/content_switches.h" |
| 17 #include "content/public/test/test_navigation_observer.h" | 19 #include "content/public/test/test_navigation_observer.h" |
| 18 #include "net/test/embedded_test_server/embedded_test_server.h" | 20 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 19 | 21 |
| 20 namespace banners { | 22 namespace banners { |
| 21 | 23 |
| 22 class TestObserver : public AppBannerDataFetcher::Observer { | 24 class TestObserver : public AppBannerDataFetcher::Observer { |
| 23 public: | 25 public: |
| 24 TestObserver(AppBannerDataFetcher* fetcher, base::Closure quit_closure) | 26 TestObserver(AppBannerDataFetcher* fetcher, base::Closure quit_closure) |
| 25 : fetcher_(fetcher), | 27 : fetcher_(fetcher), |
| 26 quit_closure_(quit_closure) { | 28 quit_closure_(quit_closure) { |
| 27 fetcher_->AddObserverForTesting(this); | 29 fetcher_->AddObserverForTesting(this); |
| 28 } | 30 } |
| 29 | 31 |
| 30 virtual ~TestObserver() { | 32 virtual ~TestObserver() { |
| 31 if (fetcher_) | 33 if (fetcher_) |
| 32 fetcher_->RemoveObserverForTesting(this); | 34 fetcher_->RemoveObserverForTesting(this); |
| 33 } | 35 } |
| 34 | 36 |
| 35 void OnDecidedWhetherToShow(AppBannerDataFetcher* fetcher, | 37 void OnDecidedWhetherToShow(AppBannerDataFetcher* fetcher, |
| 36 bool will_show) override { | 38 bool will_show) override { |
| 37 base::MessageLoop::current()->PostTask(FROM_HERE, quit_closure_); | 39 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, quit_closure_); |
| 38 ASSERT_FALSE(will_show_.get()); | 40 ASSERT_FALSE(will_show_.get()); |
| 39 will_show_.reset(new bool(will_show)); | 41 will_show_.reset(new bool(will_show)); |
| 40 } | 42 } |
| 41 | 43 |
| 42 void OnFetcherDestroyed(AppBannerDataFetcher* fetcher) override { | 44 void OnFetcherDestroyed(AppBannerDataFetcher* fetcher) override { |
| 43 base::MessageLoop::current()->PostTask(FROM_HERE, quit_closure_); | 45 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, quit_closure_); |
| 44 fetcher_ = nullptr; | 46 fetcher_ = nullptr; |
| 45 } | 47 } |
| 46 | 48 |
| 47 bool will_show() { return will_show_.get() && *will_show_; } | 49 bool will_show() { return will_show_.get() && *will_show_; } |
| 48 | 50 |
| 49 private: | 51 private: |
| 50 AppBannerDataFetcher* fetcher_; | 52 AppBannerDataFetcher* fetcher_; |
| 51 base::Closure quit_closure_; | 53 base::Closure quit_closure_; |
| 52 scoped_ptr<bool> will_show_; | 54 scoped_ptr<bool> will_show_; |
| 53 }; | 55 }; |
| 54 | 56 |
| 55 class AppBannerDataFetcherBrowserTest : public InProcessBrowserTest, | 57 class AppBannerDataFetcherBrowserTest : public InProcessBrowserTest, |
| 56 public AppBannerDataFetcher::Delegate { | 58 public AppBannerDataFetcher::Delegate { |
| 57 public: | 59 public: |
| 58 AppBannerDataFetcherBrowserTest() : weak_factory_(this) { | 60 AppBannerDataFetcherBrowserTest() : weak_factory_(this) { |
| 59 } | 61 } |
| 60 | 62 |
| 61 void SetUpOnMainThread() override { | 63 void SetUpOnMainThread() override { |
| 62 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 64 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 63 InProcessBrowserTest::SetUpOnMainThread(); | 65 InProcessBrowserTest::SetUpOnMainThread(); |
| 64 } | 66 } |
| 65 | 67 |
| 66 bool HandleNonWebApp(const std::string& platform, | 68 bool HandleNonWebApp(const std::string& platform, |
| 67 const GURL& url, | 69 const GURL& url, |
| 68 const std::string& id) override { | 70 const std::string& id) override { |
| 69 base::MessageLoop::current()->PostTask(FROM_HERE, quit_closure_); | 71 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, quit_closure_); |
| 70 non_web_platform_ = platform; | 72 non_web_platform_ = platform; |
| 71 return false; | 73 return false; |
| 72 } | 74 } |
| 73 | 75 |
| 74 void SetUpCommandLine(base::CommandLine* command_line) override { | 76 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 75 command_line->AppendSwitch( | 77 command_line->AppendSwitch( |
| 76 switches::kEnableExperimentalWebPlatformFeatures); | 78 switches::kEnableExperimentalWebPlatformFeatures); |
| 77 } | 79 } |
| 78 | 80 |
| 79 protected: | 81 protected: |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 LoadURLAndWaitForServiceWorker(test_url); | 184 LoadURLAndWaitForServiceWorker(test_url); |
| 183 RunFetcher(web_contents->GetURL(), std::string(), false); | 185 RunFetcher(web_contents->GetURL(), std::string(), false); |
| 184 | 186 |
| 185 // Advance by a day, then visit the page again to trigger the banner. | 187 // Advance by a day, then visit the page again to trigger the banner. |
| 186 AppBannerDataFetcher::SetTimeDeltaForTesting(1); | 188 AppBannerDataFetcher::SetTimeDeltaForTesting(1); |
| 187 LoadURLAndWaitForServiceWorker(test_url); | 189 LoadURLAndWaitForServiceWorker(test_url); |
| 188 RunFetcher(web_contents->GetURL(), std::string(), false); | 190 RunFetcher(web_contents->GetURL(), std::string(), false); |
| 189 } | 191 } |
| 190 | 192 |
| 191 } // namespace banners | 193 } // namespace banners |
| OLD | NEW |