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/test/ash_test_base.h" 8 #include "base/bind.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" 13 14 namespace ash { 15 namespace test { 16 17 class ScreensaverViewTest : public ash::test::AshTestBase { 18 public: ScreensaverViewTest()19 ScreensaverViewTest() { 20 url_ = GURL("http://www.google.com"); 21 webview_test_helper_.reset(new views::WebViewTestHelper()); 22 } 23 ~ScreensaverViewTest()24 virtual ~ScreensaverViewTest() {} 25 SetUp()26 virtual void SetUp() OVERRIDE { 27 AshTestBase::SetUp(); 28 RunAllPendingInMessageLoop(); 29 } 30 ExpectOpenScreensaver()31 void ExpectOpenScreensaver() { 32 ScreensaverView* screensaver = ScreensaverView::GetInstance(); 33 EXPECT_TRUE(screensaver != NULL); 34 if (!screensaver) return; 35 EXPECT_TRUE(screensaver->IsScreensaverShowingURL(url_)); 36 } 37 ExpectClosedScreensaver()38 void ExpectClosedScreensaver() { 39 EXPECT_TRUE(ScreensaverView::GetInstance() == NULL); 40 } 41 42 protected: 43 GURL url_; 44 45 private: 46 scoped_ptr<views::WebViewTestHelper> webview_test_helper_; 47 48 DISALLOW_COPY_AND_ASSIGN(ScreensaverViewTest); 49 }; 50 TEST_F(ScreensaverViewTest,ShowScreensaverAndClose)51TEST_F(ScreensaverViewTest, ShowScreensaverAndClose) { 52 ash::ShowScreensaver(url_); 53 RunAllPendingInMessageLoop(); 54 ExpectOpenScreensaver(); 55 56 ash::CloseScreensaver(); 57 ExpectClosedScreensaver(); 58 } 59 TEST_F(ScreensaverViewTest,OutOfOrderMultipleShowAndClose)60TEST_F(ScreensaverViewTest, OutOfOrderMultipleShowAndClose) { 61 ash::CloseScreensaver(); 62 ExpectClosedScreensaver(); 63 64 ash::ShowScreensaver(url_); 65 ExpectOpenScreensaver(); 66 RunAllPendingInMessageLoop(); 67 ash::ShowScreensaver(url_); 68 ExpectOpenScreensaver(); 69 RunAllPendingInMessageLoop(); 70 71 ash::CloseScreensaver(); 72 ExpectClosedScreensaver(); 73 ash::CloseScreensaver(); 74 ExpectClosedScreensaver(); 75 } 76 77 } // namespace test 78 } // namespace ash 79