Chromium Code Reviews| Index: chrome/browser/chromeos/login/merge_session_load_page_unittest.cc |
| diff --git a/chrome/browser/chromeos/login/merge_session_load_page_unittest.cc b/chrome/browser/chromeos/login/merge_session_load_page_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b72788a684246c0e7d000db5ac56a21704a968b1 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/login/merge_session_load_page_unittest.cc |
| @@ -0,0 +1,128 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/chromeos/cros/cros_library.h" |
| +#include "chrome/browser/chromeos/login/merge_session_load_page.h" |
| +#include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| +#include "content/public/browser/interstitial_page.h" |
| +#include "content/public/browser/navigation_controller.h" |
| +#include "content/public/browser/web_contents.h" |
| +#include "content/public/test/test_browser_thread.h" |
| +#include "content/public/test/web_contents_tester.h" |
| + |
| +using content::BrowserThread; |
| +using content::InterstitialPage; |
| +using content::WebContents; |
| +using content::WebContentsTester; |
| + |
| +static const char* kURL1 = "http://www.google.com/"; |
| +static const char* kURL2 = "http://mail.google.com/"; |
|
oshima
2013/02/15 22:40:52
put this in anonymous namespace. you can remove st
zel
2013/02/15 23:16:58
Done.
xiyuan
2013/02/15 23:43:07
nit: const char* kURL1 -> const char kURL1[]
zel
2013/02/15 23:51:05
Done.
|
| + |
| +namespace chromeos { |
| + |
| +class MergeSessionLoadPageTest; |
| + |
| +// An MergeSessionLoadPage class that does not create windows. |
| +class TestMergeSessionLoadPage : public chromeos::MergeSessionLoadPage { |
|
oshima
2013/02/15 22:40:52
you don't need chromeos:: namespace as you're alre
zel
2013/02/15 23:16:58
Done.
|
| + public: |
| + TestMergeSessionLoadPage(WebContents* web_contents, |
| + const GURL& url, |
| + MergeSessionLoadPageTest* test_page) |
| + : chromeos::MergeSessionLoadPage(web_contents, url, CompletionCallback()), |
| + test_page_(test_page) { |
| + interstitial_page_->DontCreateViewForTesting(); |
| + } |
| + |
| + private: |
| + MergeSessionLoadPageTest* test_page_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TestMergeSessionLoadPage); |
| +}; |
| + |
| +class MergeSessionLoadPageTest : public ChromeRenderViewHostTestHarness { |
| + public: |
| + MergeSessionLoadPageTest() |
| + : ui_thread_(BrowserThread::UI, MessageLoop::current()), |
| + file_user_blocking_thread_( |
| + BrowserThread::FILE_USER_BLOCKING, MessageLoop::current()), |
| + io_thread_(BrowserThread::IO, MessageLoop::current()) { |
| + } |
| + |
| + // ChromeRenderViewHostTestHarness overrides. |
| + virtual void SetUp() OVERRIDE { |
| + ChromeRenderViewHostTestHarness::SetUp(); |
|
oshima
2013/02/15 22:40:52
don't you have to call ChromeRenderViewHostTestHar
zel
2013/02/15 23:16:58
Actually, I don't need to override either of these
|
| + } |
| + |
| + void Navigate(const char* url, int page_id) { |
| + WebContentsTester::For(web_contents())->TestDidNavigate( |
| + web_contents()->GetRenderViewHost(), page_id, GURL(url), |
| + content::PAGE_TRANSITION_TYPED); |
| + } |
| + |
| + void ShowInterstitial(const char* url) { |
| + (new TestMergeSessionLoadPage(web_contents(), GURL(url), this))->Show(); |
| + } |
| + |
| + // Returns the MergeSessionLoadPage currently showing or NULL if none is |
| + // showing. |
| + InterstitialPage* GetMergeSessionLoadPage() { |
| + return InterstitialPage::GetInterstitialPage(web_contents()); |
| + } |
| + |
| + private: |
| + content::TestBrowserThread ui_thread_; |
| + content::TestBrowserThread file_user_blocking_thread_; |
| + content::TestBrowserThread io_thread_; |
| + |
| + // Initializes / shuts down a stub CrosLibrary. |
| + chromeos::ScopedStubCrosEnabler stub_cros_enabler_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(MergeSessionLoadPageTest); |
| +}; |
| + |
| +TEST_F(MergeSessionLoadPageTest, MergeSessionPageNotShown) { |
| + UserManager::Get()->SetMergeSessionState( |
| + UserManager::MERGE_STATUS_DONE); |
| + // Start a load. |
| + Navigate(kURL1, 1); |
| + // Load next page. |
| + controller().LoadURL(GURL(kURL2), content::Referrer(), |
| + content::PAGE_TRANSITION_TYPED, std::string()); |
| + |
| + // Simulate the load causing an merge session interstitial page |
| + // to be shown. |
| + InterstitialPage* interstitial = GetMergeSessionLoadPage(); |
| + EXPECT_FALSE(interstitial); |
| +} |
| + |
| +TEST_F(MergeSessionLoadPageTest, MergeSessionPageShown) { |
| + UserManager::Get()->SetMergeSessionState( |
| + UserManager::MERGE_STATUS_IN_PROCESS); |
| + // Start a load. |
| + Navigate(kURL1, 1); |
| + // Load next page. |
| + controller().LoadURL(GURL(kURL2), content::Referrer(), |
| + content::PAGE_TRANSITION_TYPED, std::string()); |
| + |
| + // Simulate the load causing an merge session interstitial page |
| + // to be shown. |
| + ShowInterstitial(kURL2); |
| + InterstitialPage* interstitial = GetMergeSessionLoadPage(); |
| + ASSERT_TRUE(interstitial); |
| + MessageLoop::current()->RunUntilIdle(); |
| + |
| + // Simulate merge session completion. |
| + UserManager::Get()->SetMergeSessionState( |
| + UserManager::MERGE_STATUS_DONE); |
| + MessageLoop::current()->RunUntilIdle(); |
| + |
| + // The URL remains to be URL2. |
| + EXPECT_EQ(kURL2, web_contents()->GetURL().spec()); |
| + |
| + // Commit navigation and the interstitial page is gone. |
| + Navigate(kURL2, 2); |
| + EXPECT_FALSE(GetMergeSessionLoadPage()); |
| +} |
| + |
| +} // namespace chromeos |