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 "base/command_line.h" 6 #include "base/path_service.h" 7 #include "base/process/kill.h" 8 #include "base/process/launch.h" 9 #include "base/test/test_timeouts.h" 10 #include "chrome/browser/chrome_notification_types.h" 11 #include "chrome/common/chrome_result_codes.h" 12 #include "chrome/common/chrome_switches.h" 13 #include "chrome/test/base/in_process_browser_test.h" 14 #include "chrome/test/base/test_switches.h" 15 #include "chrome/test/base/ui_test_utils.h" 16 #include "content/public/browser/notification_service.h" 17 #include "content/public/common/result_codes.h" 18 19 // These tests don't apply to the Mac version; see GetCommandLineForRelaunch 20 // for details. 21 #if defined(OS_MACOSX) 22 #error This test file should not be part of the Mac build. 23 #endif 24 25 namespace { 26 27 class CloudPrintPolicyTest : public InProcessBrowserTest { 28 public: 29 CloudPrintPolicyTest() {} 30 }; 31 32 IN_PROC_BROWSER_TEST_F(CloudPrintPolicyTest, NormalPassedFlag) { 33 #if defined(OS_WIN) && defined(USE_ASH) 34 // Disable this test in Metro+Ash for now (http://crbug.com/262796). 35 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) 36 return; 37 #endif 38 39 base::FilePath test_file_path = ui_test_utils::GetTestFilePath( 40 base::FilePath(), base::FilePath().AppendASCII("empty.html")); 41 CommandLine new_command_line(GetCommandLineForRelaunch()); 42 new_command_line.AppendArgPath(test_file_path); 43 44 content::WindowedNotificationObserver observer( 45 chrome::NOTIFICATION_TAB_ADDED, 46 content::NotificationService::AllSources()); 47 48 base::ProcessHandle handle; 49 bool launched = 50 base::LaunchProcess(new_command_line, base::LaunchOptions(), &handle); 51 EXPECT_TRUE(launched); 52 53 observer.Wait(); 54 55 int exit_code = -100; 56 bool exited = 57 base::WaitForExitCodeWithTimeout(handle, &exit_code, 58 TestTimeouts::action_timeout()); 59 60 EXPECT_TRUE(exited); 61 EXPECT_EQ(chrome::RESULT_CODE_NORMAL_EXIT_PROCESS_NOTIFIED, exit_code); 62 base::CloseProcessHandle(handle); 63 } 64 65 // Disabled due to http://crbug.com/144393. 66 IN_PROC_BROWSER_TEST_F(CloudPrintPolicyTest, DISABLED_CloudPrintPolicyFlag) { 67 CommandLine new_command_line(GetCommandLineForRelaunch()); 68 new_command_line.AppendSwitch(switches::kCheckCloudPrintConnectorPolicy); 69 // This is important for the test as the way the browser process is launched 70 // here causes the predictor databases to be initialized multiple times. This 71 // is not an issue for production where the process is launched as a service 72 // and a Profile is not created. See http://crbug.com/140466 for more details. 73 new_command_line.AppendSwitchASCII( 74 switches::kSpeculativeResourcePrefetching, 75 switches::kSpeculativeResourcePrefetchingDisabled); 76 77 base::ProcessHandle handle; 78 bool launched = 79 base::LaunchProcess(new_command_line, base::LaunchOptions(), &handle); 80 EXPECT_TRUE(launched); 81 82 int exit_code = -100; 83 bool exited = 84 base::WaitForExitCodeWithTimeout(handle, &exit_code, 85 TestTimeouts::action_timeout()); 86 87 EXPECT_TRUE(exited); 88 EXPECT_EQ(content::RESULT_CODE_NORMAL_EXIT, exit_code); 89 base::CloseProcessHandle(handle); 90 } 91 92 } // namespace 93