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.
5 #include "base/command_line.h"
6 #include "base/process/kill.h"
7 #include "base/process/launch.h"
8 #include "base/test/test_timeouts.h"
9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/common/chrome_result_codes.h"
11 #include "chrome/common/chrome_switches.h"
12 #include "chrome/test/base/in_process_browser_test.h"
13 #include "chrome/test/base/test_switches.h"
14 #include "chrome/test/base/ui_test_utils.h"
15 #include "content/public/browser/notification_service.h"
16 #include "content/public/common/result_codes.h"
18 // These tests don't apply to the Mac version; see GetCommandLineForRelaunch
20 #if defined(OS_MACOSX)
21 #error This test file should not be part of the Mac build.
26 class CloudPrintPolicyTest : public InProcessBrowserTest {
28 CloudPrintPolicyTest() {}
31 IN_PROC_BROWSER_TEST_F(CloudPrintPolicyTest, NormalPassedFlag) {
32 #if defined(OS_WIN) && defined(USE_ASH)
33 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
34 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
38 base::FilePath test_file_path = ui_test_utils::GetTestFilePath(
39 base::FilePath(), base::FilePath().AppendASCII("empty.html"));
40 CommandLine new_command_line(GetCommandLineForRelaunch());
41 new_command_line.AppendArgPath(test_file_path);
43 content::WindowedNotificationObserver observer(
44 chrome::NOTIFICATION_TAB_ADDED,
45 content::NotificationService::AllSources());
47 base::ProcessHandle handle;
49 base::LaunchProcess(new_command_line, base::LaunchOptionsForTest(),
51 EXPECT_TRUE(launched);
57 base::WaitForExitCodeWithTimeout(handle, &exit_code,
58 TestTimeouts::action_timeout());
61 EXPECT_EQ(chrome::RESULT_CODE_NORMAL_EXIT_PROCESS_NOTIFIED, exit_code);
62 base::CloseProcessHandle(handle);
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);
77 base::ProcessHandle handle;
79 base::LaunchProcess(new_command_line, base::LaunchOptionsForTest(),
81 EXPECT_TRUE(launched);
85 base::WaitForExitCodeWithTimeout(handle, &exit_code,
86 TestTimeouts::action_timeout());
89 EXPECT_EQ(content::RESULT_CODE_NORMAL_EXIT, exit_code);
90 base::CloseProcessHandle(handle);