Index: ash/screensaver/screensaver_view_unittest.cc |
diff --git a/ash/screensaver/screensaver_view_unittest.cc b/ash/screensaver/screensaver_view_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4b1383b5925b230ed0571c4f0e905d8803a7a0f9 |
--- /dev/null |
+++ b/ash/screensaver/screensaver_view_unittest.cc |
@@ -0,0 +1,113 @@ |
+// Copyright (c) 2012 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 "ash/screensaver/screensaver_view.h" |
+ |
+#include "ash/screensaver/test_webview.h" |
+#include "ash/test/ash_test_base.h" |
+#include "base/bind.h" |
+#include "content/public/browser/browser_context.h" |
+#include "content/test/mock_render_process_host.h" |
+#include "content/test/test_browser_thread.h" |
+#include "content/test/test_content_client_initializer.h" |
+#include "content/test/test_render_view_host_factory.h" |
+ |
+namespace ash { |
+namespace test { |
+ |
+class ScreensaverViewTest : public ash::test::AshTestBase { |
Ben Goodger (Google)
2012/05/01 16:57:42
can you create a helper class in views test suppor
|
+ public: |
+ ScreensaverViewTest() |
+ : rph_factory_(new content::MockRenderProcessHostFactory()), |
+ rvh_factory_( |
+ new content::TestRenderViewHostFactory(rph_factory_.get())) { |
+ url_ = GURL("http://www.google.com"); |
+ |
+ test_content_client_initializer_.reset(new TestContentClientInitializer); |
+ |
+ MessageLoopForUI* ui_loop = message_loop(); |
+ ui_thread_.reset( |
+ new content::TestBrowserThread(content::BrowserThread::UI, ui_loop)); |
+ |
+ internal::ScreensaverView::webview_factory_ = |
+ base::Bind(ScreensaverViewTest::CreateTestWebView); |
+ } |
+ |
+ virtual ~ScreensaverViewTest() {} |
+ |
+ virtual void SetUp() OVERRIDE { |
+ AshTestBase::SetUp(); |
+ RunAllPendingInMessageLoop(); |
+ } |
+ |
+ virtual void TearDown() OVERRIDE { |
+ AshTestBase::TearDown(); |
+ } |
+ |
+ void ExpectOpenScreensaver() { |
+ internal::ScreensaverView* screensaver = |
+ internal::ScreensaverView::GetInstance(); |
+ EXPECT_TRUE(screensaver != NULL); |
+ if (!screensaver) return; |
+ |
+ EXPECT_TRUE(screensaver->screensaver_webview_ != NULL); |
+ if (!screensaver->screensaver_webview_) return; |
+ |
+ EXPECT_TRUE(screensaver->screensaver_webview_->web_contents() != NULL); |
+ if (!screensaver->screensaver_webview_->web_contents()) return; |
+ |
+ EXPECT_EQ(screensaver->screensaver_webview_->web_contents()->GetURL(), |
+ url_); |
+ } |
+ |
+ void ExpectClosedScreensaver() { |
+ EXPECT_TRUE(internal::ScreensaverView::GetInstance() == NULL); |
+ } |
+ |
+ static views::WebView* CreateTestWebView(content::BrowserContext* context) { |
+ return new TestWebView(context); |
+ } |
+ |
+ protected: |
+ GURL url_; |
+ |
+ private: |
+ scoped_ptr<TestContentClientInitializer> test_content_client_initializer_; |
+ |
+ scoped_ptr<content::TestBrowserThread> ui_thread_; |
+ |
+ scoped_ptr<content::MockRenderProcessHostFactory> rph_factory_; |
+ scoped_ptr<content::TestRenderViewHostFactory> rvh_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ScreensaverViewTest); |
+}; |
+ |
+TEST_F(ScreensaverViewTest, ShowScreensaverAndClose) { |
+ ash::ShowScreensaver(url_); |
+ RunAllPendingInMessageLoop(); |
+ ExpectOpenScreensaver(); |
+ |
+ ash::CloseScreensaver(); |
+ ExpectClosedScreensaver(); |
+} |
+ |
+TEST_F(ScreensaverViewTest, OutOfOrderMultipleShowAndClose) { |
+ ash::CloseScreensaver(); |
+ ExpectClosedScreensaver(); |
+ |
+ ash::ShowScreensaver(url_); |
+ ExpectOpenScreensaver(); |
+ RunAllPendingInMessageLoop(); |
+ ash::ShowScreensaver(url_); |
+ ExpectOpenScreensaver(); |
+ RunAllPendingInMessageLoop(); |
+ |
+ ash::CloseScreensaver(); |
+ ExpectClosedScreensaver(); |
+ ash::CloseScreensaver(); |
+ ExpectClosedScreensaver(); |
+} |
+ |
+} // namespace test |
+} // namespace ash |