OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ash/screensaver/screensaver_view.h" | |
6 | |
7 #include "ash/screensaver/test_webview.h" | |
8 #include "ash/test/ash_test_base.h" | |
9 #include "base/bind.h" | |
10 #include "content/public/browser/browser_context.h" | |
11 #include "content/test/mock_render_process_host.h" | |
12 #include "content/test/test_browser_thread.h" | |
13 #include "content/test/test_content_client_initializer.h" | |
14 #include "content/test/test_render_view_host_factory.h" | |
15 | |
16 namespace ash { | |
17 namespace test { | |
18 | |
19 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
| |
20 public: | |
21 ScreensaverViewTest() | |
22 : rph_factory_(new content::MockRenderProcessHostFactory()), | |
23 rvh_factory_( | |
24 new content::TestRenderViewHostFactory(rph_factory_.get())) { | |
25 url_ = GURL("http://www.google.com"); | |
26 | |
27 test_content_client_initializer_.reset(new TestContentClientInitializer); | |
28 | |
29 MessageLoopForUI* ui_loop = message_loop(); | |
30 ui_thread_.reset( | |
31 new content::TestBrowserThread(content::BrowserThread::UI, ui_loop)); | |
32 | |
33 internal::ScreensaverView::webview_factory_ = | |
34 base::Bind(ScreensaverViewTest::CreateTestWebView); | |
35 } | |
36 | |
37 virtual ~ScreensaverViewTest() {} | |
38 | |
39 virtual void SetUp() OVERRIDE { | |
40 AshTestBase::SetUp(); | |
41 RunAllPendingInMessageLoop(); | |
42 } | |
43 | |
44 virtual void TearDown() OVERRIDE { | |
45 AshTestBase::TearDown(); | |
46 } | |
47 | |
48 void ExpectOpenScreensaver() { | |
49 internal::ScreensaverView* screensaver = | |
50 internal::ScreensaverView::GetInstance(); | |
51 EXPECT_TRUE(screensaver != NULL); | |
52 if (!screensaver) return; | |
53 | |
54 EXPECT_TRUE(screensaver->screensaver_webview_ != NULL); | |
55 if (!screensaver->screensaver_webview_) return; | |
56 | |
57 EXPECT_TRUE(screensaver->screensaver_webview_->web_contents() != NULL); | |
58 if (!screensaver->screensaver_webview_->web_contents()) return; | |
59 | |
60 EXPECT_EQ(screensaver->screensaver_webview_->web_contents()->GetURL(), | |
61 url_); | |
62 } | |
63 | |
64 void ExpectClosedScreensaver() { | |
65 EXPECT_TRUE(internal::ScreensaverView::GetInstance() == NULL); | |
66 } | |
67 | |
68 static views::WebView* CreateTestWebView(content::BrowserContext* context) { | |
69 return new TestWebView(context); | |
70 } | |
71 | |
72 protected: | |
73 GURL url_; | |
74 | |
75 private: | |
76 scoped_ptr<TestContentClientInitializer> test_content_client_initializer_; | |
77 | |
78 scoped_ptr<content::TestBrowserThread> ui_thread_; | |
79 | |
80 scoped_ptr<content::MockRenderProcessHostFactory> rph_factory_; | |
81 scoped_ptr<content::TestRenderViewHostFactory> rvh_factory_; | |
82 | |
83 DISALLOW_COPY_AND_ASSIGN(ScreensaverViewTest); | |
84 }; | |
85 | |
86 TEST_F(ScreensaverViewTest, ShowScreensaverAndClose) { | |
87 ash::ShowScreensaver(url_); | |
88 RunAllPendingInMessageLoop(); | |
89 ExpectOpenScreensaver(); | |
90 | |
91 ash::CloseScreensaver(); | |
92 ExpectClosedScreensaver(); | |
93 } | |
94 | |
95 TEST_F(ScreensaverViewTest, OutOfOrderMultipleShowAndClose) { | |
96 ash::CloseScreensaver(); | |
97 ExpectClosedScreensaver(); | |
98 | |
99 ash::ShowScreensaver(url_); | |
100 ExpectOpenScreensaver(); | |
101 RunAllPendingInMessageLoop(); | |
102 ash::ShowScreensaver(url_); | |
103 ExpectOpenScreensaver(); | |
104 RunAllPendingInMessageLoop(); | |
105 | |
106 ash::CloseScreensaver(); | |
107 ExpectClosedScreensaver(); | |
108 ash::CloseScreensaver(); | |
109 ExpectClosedScreensaver(); | |
110 } | |
111 | |
112 } // namespace test | |
113 } // namespace ash | |
OLD | NEW |