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