Upstream version 7.36.149.0
[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/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
71   base::ProcessHandle handle;
72   bool launched =
73       base::LaunchProcess(new_command_line, base::LaunchOptionsForTest(),
74           &handle);
75   EXPECT_TRUE(launched);
76
77   int exit_code = -100;
78   bool exited =
79       base::WaitForExitCodeWithTimeout(handle, &exit_code,
80                                        TestTimeouts::action_timeout());
81
82   EXPECT_TRUE(exited);
83   EXPECT_EQ(content::RESULT_CODE_NORMAL_EXIT, exit_code);
84   base::CloseProcessHandle(handle);
85 }
86
87 }  // namespace