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::LaunchOptionsForTest(), 51 &handle); 52 EXPECT_TRUE(launched); 53 54 observer.Wait(); 55 56 int exit_code = -100; 57 bool exited = 58 base::WaitForExitCodeWithTimeout(handle, &exit_code, 59 TestTimeouts::action_timeout()); 60 61 EXPECT_TRUE(exited); 62 EXPECT_EQ(chrome::RESULT_CODE_NORMAL_EXIT_PROCESS_NOTIFIED, exit_code); 63 base::CloseProcessHandle(handle); 64 } 65 66 // Disabled due to http://crbug.com/144393. 67 IN_PROC_BROWSER_TEST_F(CloudPrintPolicyTest, DISABLED_CloudPrintPolicyFlag) { 68 CommandLine new_command_line(GetCommandLineForRelaunch()); 69 new_command_line.AppendSwitch(switches::kCheckCloudPrintConnectorPolicy); 70 // This is important for the test as the way the browser process is launched 71 // here causes the predictor databases to be initialized multiple times. This 72 // is not an issue for production where the process is launched as a service 73 // and a Profile is not created. See http://crbug.com/140466 for more details. 74 new_command_line.AppendSwitchASCII( 75 switches::kSpeculativeResourcePrefetching, 76 switches::kSpeculativeResourcePrefetchingDisabled); 77 78 base::ProcessHandle handle; 79 bool launched = 80 base::LaunchProcess(new_command_line, base::LaunchOptionsForTest(), 81 &handle); 82 EXPECT_TRUE(launched); 83 84 int exit_code = -100; 85 bool exited = 86 base::WaitForExitCodeWithTimeout(handle, &exit_code, 87 TestTimeouts::action_timeout()); 88 89 EXPECT_TRUE(exited); 90 EXPECT_EQ(content::RESULT_CODE_NORMAL_EXIT, exit_code); 91 base::CloseProcessHandle(handle); 92 } 93 94 } // namespace 95