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.
5 #include "ash/screensaver/screensaver_view.h"
7 #include "ash/test/ash_test_base.h"
9 #include "content/public/browser/browser_context.h"
10 #include "content/public/browser/web_contents.h"
11 #include "ui/views/controls/webview/webview.h"
12 #include "ui/views/test/webview_test_helper.h"
17 class ScreensaverViewTest
: public ash::test::AshTestBase
{
19 ScreensaverViewTest() {
20 url_
= GURL("http://www.google.com");
21 webview_test_helper_
.reset(new views::WebViewTestHelper());
24 virtual ~ScreensaverViewTest() {}
26 virtual void SetUp() override
{
28 RunAllPendingInMessageLoop();
31 void ExpectOpenScreensaver() {
32 ScreensaverView
* screensaver
= ScreensaverView::GetInstance();
33 EXPECT_TRUE(screensaver
!= NULL
);
34 if (!screensaver
) return;
35 EXPECT_TRUE(screensaver
->IsScreensaverShowingURL(url_
));
38 void ExpectClosedScreensaver() {
39 EXPECT_TRUE(ScreensaverView::GetInstance() == NULL
);
46 scoped_ptr
<views::WebViewTestHelper
> webview_test_helper_
;
48 DISALLOW_COPY_AND_ASSIGN(ScreensaverViewTest
);
51 TEST_F(ScreensaverViewTest
, ShowScreensaverAndClose
) {
52 ash::ShowScreensaver(url_
);
53 RunAllPendingInMessageLoop();
54 ExpectOpenScreensaver();
56 ash::CloseScreensaver();
57 ExpectClosedScreensaver();
60 TEST_F(ScreensaverViewTest
, OutOfOrderMultipleShowAndClose
) {
61 ash::CloseScreensaver();
62 ExpectClosedScreensaver();
64 ash::ShowScreensaver(url_
);
65 ExpectOpenScreensaver();
66 RunAllPendingInMessageLoop();
67 ash::ShowScreensaver(url_
);
68 ExpectOpenScreensaver();
69 RunAllPendingInMessageLoop();
71 ash::CloseScreensaver();
72 ExpectClosedScreensaver();
73 ash::CloseScreensaver();
74 ExpectClosedScreensaver();