dc29c06449fdc8b31f148ab103bcc9047d20112a
[platform/framework/web/crosswalk.git] / src / chrome / browser / printing / cloud_print / test / cloud_print_policy_browsertest.cc
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/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"
17
18 // These tests don't apply to the Mac version; see GetCommandLineForRelaunch
19 // for details.
20 #if defined(OS_MACOSX)
21 #error This test file should not be part of the Mac build.
22 #endif
23
24 namespace {
25
26 class CloudPrintPolicyTest : public InProcessBrowserTest {
27  public:
28   CloudPrintPolicyTest() {}
29 };
30
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))
35     return;
36 #endif
37
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);
42
43   content::WindowedNotificationObserver observer(
44       chrome::NOTIFICATION_TAB_ADDED,
45       content::NotificationService::AllSources());
46
47   base::ProcessHandle handle;
48   bool launched =
49       base::LaunchProcess(new_command_line, base::LaunchOptionsForTest(),
50           &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::LaunchOptionsForTest(),
80           &handle);
81   EXPECT_TRUE(launched);
82
83   int exit_code = -100;
84   bool exited =
85       base::WaitForExitCodeWithTimeout(handle, &exit_code,
86                                        TestTimeouts::action_timeout());
87
88   EXPECT_TRUE(exited);
89   EXPECT_EQ(content::RESULT_CODE_NORMAL_EXIT, exit_code);
90   base::CloseProcessHandle(handle);
91 }
92
93 }  // namespace