demo_app_launcher_browsertest.cc revision 1320f92c476a1ad9d19dba2a48c72b75566198e9
1// Copyright 2014 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 "base/basictypes.h" 6#include "base/command_line.h" 7#include "base/compiler_specific.h" 8#include "base/files/file_path.h" 9#include "base/path_service.h" 10#include "chrome/browser/chrome_notification_types.h" 11#include "chrome/browser/chromeos/login/demo_mode/demo_app_launcher.h" 12#include "chrome/browser/chromeos/login/test/app_window_waiter.h" 13#include "chrome/browser/extensions/extension_browsertest.h" 14#include "chrome/browser/profiles/profile.h" 15#include "chrome/browser/profiles/profile_manager.h" 16#include "chrome/common/chrome_paths.h" 17#include "chromeos/chromeos_switches.h" 18#include "chromeos/network/network_state.h" 19#include "chromeos/network/network_state_handler.h" 20#include "components/user_manager/user_manager.h" 21#include "content/public/browser/notification_service.h" 22#include "content/public/browser/notification_source.h" 23#include "content/public/test/test_utils.h" 24#include "extensions/browser/app_window/app_window_registry.h" 25#include "testing/gtest/include/gtest/gtest.h" 26 27namespace chromeos { 28 29namespace { 30 31base::FilePath GetTestDemoAppPath() { 32 base::FilePath test_data_dir; 33 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)); 34 return test_data_dir.Append(FILE_PATH_LITERAL("chromeos/demo_app")); 35} 36 37Profile* WaitForProfile() { 38 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); 39 if (!user_manager || !user_manager->IsUserLoggedIn()) { 40 content::WindowedNotificationObserver( 41 chrome::NOTIFICATION_SESSION_STARTED, 42 content::NotificationService::AllSources()).Wait(); 43 } 44 45 return ProfileManager::GetActiveUserProfile(); 46} 47 48bool VerifyDemoAppLaunch() { 49 Profile* profile = WaitForProfile(); 50 return AppWindowWaiter(extensions::AppWindowRegistry::Get(profile), 51 DemoAppLauncher::kDemoAppId).Wait() != NULL; 52} 53 54bool VerifyNetworksDisabled() { 55 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); 56 return !handler->FirstNetworkByType(NetworkTypePattern::NonVirtual()); 57} 58 59} // namespace 60 61class DemoAppLauncherTest : public ExtensionBrowserTest { 62 public: 63 DemoAppLauncherTest() { 64 set_exit_when_last_browser_closes(false); 65 } 66 67 virtual ~DemoAppLauncherTest() {} 68 69 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 70 command_line->AppendSwitch(switches::kLoginManager); 71 command_line->AppendSwitch(switches::kForceLoginManagerInTests); 72 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); 73 74 command_line->AppendSwitchASCII(switches::kDerelictIdleTimeout, "0"); 75 command_line->AppendSwitchASCII(switches::kOobeTimerInterval, "0"); 76 command_line->AppendSwitchASCII(switches::kDerelictDetectionTimeout, "0"); 77 } 78 79 virtual void SetUp() OVERRIDE { 80 chromeos::DemoAppLauncher::SetDemoAppPathForTesting(GetTestDemoAppPath()); 81 ExtensionBrowserTest::SetUp(); 82 } 83 84 private: 85 DISALLOW_COPY_AND_ASSIGN(DemoAppLauncherTest); 86}; 87 88IN_PROC_BROWSER_TEST_F(DemoAppLauncherTest, Basic) { 89 // This test is fairly unique in the sense that the test actually starts as 90 // soon as Chrome launches, so there isn't any typical "launch this test" 91 // steps that we need to take. All we can do is verify that our demo app 92 // did launch. 93 EXPECT_TRUE(VerifyDemoAppLaunch()); 94} 95 96IN_PROC_BROWSER_TEST_F(DemoAppLauncherTest, NoNetwork) { 97 EXPECT_TRUE(VerifyDemoAppLaunch()); 98 EXPECT_TRUE(VerifyNetworksDisabled()); 99} 100 101} // namespace chromeos 102