Home | History | Annotate | Download | only in screensaver
      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 "chrome/browser/chromeos/screensaver/screensaver_controller.h"
      6 
      7 #include "ash/screensaver/screensaver_view.h"
      8 #include "chrome/browser/extensions/extension_browsertest.h"
      9 #include "chrome/browser/extensions/extension_service.h"
     10 #include "chrome/browser/profiles/profile_manager.h"
     11 #include "chrome/common/extensions/extension_builder.h"
     12 #include "chrome/common/extensions/value_builder.h"
     13 #include "chrome/test/base/in_process_browser_test.h"
     14 
     15 namespace {
     16 
     17 scoped_refptr<extensions::Extension> CreateTestScreensaverExtension() {
     18   scoped_refptr<extensions::Extension> extension =
     19       extensions::ExtensionBuilder()
     20       .SetPath(base::FilePath())
     21       .SetManifest(extensions::DictionaryBuilder()
     22                    .Set("name", "Screensaver Extension")
     23                    .Set("version", "1")
     24                    .Set("manifest_version", 2)
     25                    .Set("app", extensions::DictionaryBuilder()
     26                        .Set("launch", extensions::DictionaryBuilder()
     27                            .Set("local_path", "")))
     28                    .Set("permissions", extensions::ListBuilder()
     29                         .Append("screensaver")))
     30       .Build();
     31 
     32   return extension;
     33 }
     34 
     35 void InstallExtensionToDefaultProfile(const extensions::Extension* extension) {
     36   Profile* default_profile = ProfileManager::GetDefaultProfile();
     37   EXPECT_TRUE(default_profile);
     38   ExtensionService* service =
     39       extensions::ExtensionSystem::Get(default_profile)->extension_service();
     40   EXPECT_TRUE(service);
     41 
     42   service->AddExtension(extension);
     43 }
     44 
     45 } // namespace
     46 
     47 namespace chromeos {
     48 
     49 class ScreensaverControllerTest : public InProcessBrowserTest {
     50 };
     51 
     52 IN_PROC_BROWSER_TEST_F(ScreensaverControllerTest, Basic) {
     53   scoped_refptr<extensions::Extension> extension(
     54       CreateTestScreensaverExtension());
     55   InstallExtensionToDefaultProfile(extension.get());
     56 
     57   scoped_ptr<ScreensaverController> controller_;
     58   controller_.reset(new ScreensaverController());
     59   base::MessageLoop::current()->RunUntilIdle();
     60 
     61   // Trigger idle.
     62   controller_->IdleNotify(0);
     63   EXPECT_TRUE(ash::IsScreensaverShown());
     64 
     65   // Trigger active.
     66   controller_->OnUserActivity(NULL);
     67   EXPECT_FALSE(ash::IsScreensaverShown());
     68 };
     69 
     70 IN_PROC_BROWSER_TEST_F(ScreensaverControllerTest, OutOfOrder) {
     71   scoped_refptr<extensions::Extension> extension(
     72       CreateTestScreensaverExtension());
     73   InstallExtensionToDefaultProfile(extension.get());
     74 
     75   scoped_ptr<ScreensaverController> controller_;
     76   controller_.reset(new ScreensaverController());
     77   base::MessageLoop::current()->RunUntilIdle();
     78 
     79   // Trigger active.
     80   controller_->OnUserActivity(NULL);
     81   EXPECT_FALSE(ash::IsScreensaverShown());
     82 
     83   // Trigger idle.
     84   controller_->IdleNotify(0);
     85   EXPECT_TRUE(ash::IsScreensaverShown());
     86 
     87 
     88   // Trigger idle.
     89   controller_->IdleNotify(0);
     90   EXPECT_TRUE(ash::IsScreensaverShown());
     91 
     92   // Trigger active.
     93   controller_->OnUserActivity(NULL);
     94   EXPECT_FALSE(ash::IsScreensaverShown());
     95 };
     96 
     97 }  // namespace chromeos.
     98