OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/base_paths.h" | 5 #include "base/base_paths.h" |
6 #include "base/file_path.h" | 6 #include "base/file_path.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/sys_info.h" | 10 #include "base/sys_info.h" |
11 #include "base/test/test_file_util.h" | 11 #include "base/test/test_file_util.h" |
12 #include "base/test/test_timeouts.h" | 12 #include "base/test/test_timeouts.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/app/chrome_command_ids.h" | 14 #include "chrome/app/chrome_command_ids.h" |
15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/common/chrome_constants.h" | 16 #include "chrome/common/chrome_constants.h" |
17 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
18 #include "chrome/common/pref_names.h" | |
19 #include "chrome/test/automation/automation_proxy.h" | 18 #include "chrome/test/automation/automation_proxy.h" |
20 #include "chrome/test/automation/browser_proxy.h" | 19 #include "chrome/test/automation/browser_proxy.h" |
21 #include "chrome/test/automation/tab_proxy.h" | 20 #include "chrome/test/automation/tab_proxy.h" |
22 #include "chrome/test/automation/window_proxy.h" | 21 #include "chrome/test/automation/window_proxy.h" |
23 #include "chrome/test/ui/ui_test.h" | 22 #include "chrome/test/ui/ui_test.h" |
24 #include "grit/chromium_strings.h" | 23 #include "grit/chromium_strings.h" |
25 #include "grit/generated_resources.h" | 24 #include "grit/generated_resources.h" |
26 #include "net/base/net_util.h" | 25 #include "net/base/net_util.h" |
27 #include "net/test/test_server.h" | 26 #include "net/test/test_server.h" |
28 #include "ui/gfx/native_widget_types.h" | 27 #include "ui/gfx/native_widget_types.h" |
29 | 28 |
30 namespace { | 29 namespace { |
31 | 30 |
32 class BrowserTest : public UITest { | 31 class BrowserTest : public UITest { |
33 }; | 32 }; |
34 | 33 |
35 class VisibleBrowserTest : public UITest { | 34 class VisibleBrowserTest : public UITest { |
36 protected: | 35 protected: |
37 VisibleBrowserTest() : UITest() { | 36 VisibleBrowserTest() : UITest() { |
38 show_window_ = true; | 37 show_window_ = true; |
39 } | 38 } |
40 }; | 39 }; |
41 | 40 |
42 #if defined(OS_WIN) | 41 } // namespace |
43 // The browser should quit quickly if it receives a WM_ENDSESSION message. | 42 |
44 TEST_F(BrowserTest, WindowsSessionEnd) { | 43 // The browser should quit quickly if it receives a WM_ENDSESSION message |
45 #elif defined(OS_POSIX) | 44 // on Windows, or SIGTERM on posix. |
46 // The browser should quit gracefully and quickly if it receives a SIGTERM. | 45 TEST_F(BrowserTest, SessionEnd) { |
47 TEST_F(BrowserTest, PosixSessionEnd) { | |
48 #endif | |
49 FilePath test_file(test_data_directory_); | 46 FilePath test_file(test_data_directory_); |
50 test_file = test_file.AppendASCII("title1.html"); | 47 test_file = test_file.AppendASCII("title1.html"); |
51 | 48 |
52 NavigateToURL(net::FilePathToFileURL(test_file)); | 49 NavigateToURL(net::FilePathToFileURL(test_file)); |
53 TerminateBrowser(); | 50 TerminateBrowser(); |
54 | 51 VerifyCleanExit(); |
55 // Make sure the UMA metrics say we didn't crash. | |
56 scoped_ptr<DictionaryValue> local_prefs(GetLocalState()); | |
57 bool exited_cleanly; | |
58 ASSERT_TRUE(local_prefs.get()); | |
59 ASSERT_TRUE(local_prefs->GetBoolean(prefs::kStabilityExitedCleanly, | |
60 &exited_cleanly)); | |
61 ASSERT_TRUE(exited_cleanly); | |
62 | |
63 // And that session end was successful. | |
64 bool session_end_completed; | |
65 ASSERT_TRUE(local_prefs->GetBoolean(prefs::kStabilitySessionEndCompleted, | |
66 &session_end_completed)); | |
67 ASSERT_TRUE(session_end_completed); | |
68 | |
69 // Make sure session restore says we didn't crash. | |
70 scoped_ptr<DictionaryValue> profile_prefs(GetDefaultProfilePreferences()); | |
71 ASSERT_TRUE(profile_prefs.get()); | |
72 ASSERT_TRUE(profile_prefs->GetBoolean(prefs::kSessionExitedCleanly, | |
73 &exited_cleanly)); | |
74 ASSERT_TRUE(exited_cleanly); | |
75 } | 52 } |
76 | 53 |
77 // WindowOpenClose is flaky on ChromeOS and fails consistently on linux views. | 54 // WindowOpenClose is flaky on ChromeOS and fails consistently on linux views. |
78 // See http://crbug.com/85763. | 55 // See http://crbug.com/85763. |
79 #if defined (OS_CHROMEOS) | 56 #if defined (OS_CHROMEOS) |
80 #define MAYBE_WindowOpenClose FLAKY_WindowOpenClose | 57 #define MAYBE_WindowOpenClose FLAKY_WindowOpenClose |
81 #elif defined(OS_LINUX) && defined(TOOLKIT_VIEWS) | 58 #elif defined(OS_LINUX) && defined(TOOLKIT_VIEWS) |
82 #define MAYBE_WindowOpenClose FAILS_WindowOpenClose | 59 #define MAYBE_WindowOpenClose FAILS_WindowOpenClose |
83 #else | 60 #else |
84 #define MAYBE_WindowOpenClose WindowOpenClose | 61 #define MAYBE_WindowOpenClose WindowOpenClose |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 int window_count; | 218 int window_count; |
242 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); | 219 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); |
243 EXPECT_EQ(0, window_count); | 220 EXPECT_EQ(0, window_count); |
244 | 221 |
245 // Starting a browser window should work just fine. | 222 // Starting a browser window should work just fine. |
246 ASSERT_TRUE(automation()->OpenNewBrowserWindow(Browser::TYPE_TABBED, true)); | 223 ASSERT_TRUE(automation()->OpenNewBrowserWindow(Browser::TYPE_TABBED, true)); |
247 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); | 224 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); |
248 EXPECT_EQ(1, window_count); | 225 EXPECT_EQ(1, window_count); |
249 } | 226 } |
250 | 227 |
251 } // namespace | |
252 | |
253 // This test needs to be placed outside the anonymouse namespace because we | 228 // This test needs to be placed outside the anonymouse namespace because we |
254 // need to access private type of Browser. | 229 // need to access private type of Browser. |
255 class AppModeTest : public UITest { | 230 class AppModeTest : public UITest { |
256 public: | 231 public: |
257 AppModeTest() { | 232 AppModeTest() { |
258 // Load a local file. | 233 // Load a local file. |
259 FilePath test_file(test_data_directory_); | 234 FilePath test_file(test_data_directory_); |
260 test_file = test_file.AppendASCII("title1.html"); | 235 test_file = test_file.AppendASCII("title1.html"); |
261 GURL test_file_url(net::FilePathToFileURL(test_file)); | 236 GURL test_file_url(net::FilePathToFileURL(test_file)); |
262 | 237 |
263 launch_arguments_.AppendSwitchASCII(switches::kApp, test_file_url.spec()); | 238 launch_arguments_.AppendSwitchASCII(switches::kApp, test_file_url.spec()); |
264 } | 239 } |
265 }; | 240 }; |
266 | 241 |
267 TEST_F(AppModeTest, EnableAppModeTest) { | 242 TEST_F(AppModeTest, EnableAppModeTest) { |
268 // Test that an application browser window loads correctly. | 243 // Test that an application browser window loads correctly. |
269 | 244 |
270 // Verify that the window is present. | 245 // Verify that the window is present. |
271 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | 246 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
272 ASSERT_TRUE(browser.get()); | 247 ASSERT_TRUE(browser.get()); |
273 | 248 |
274 // Verify the browser is in application mode. | 249 // Verify the browser is in application mode. |
275 bool is_application; | 250 bool is_application; |
276 ASSERT_TRUE(browser->IsApplication(&is_application)); | 251 ASSERT_TRUE(browser->IsApplication(&is_application)); |
277 EXPECT_TRUE(is_application); | 252 EXPECT_TRUE(is_application); |
278 } | 253 } |
OLD | NEW |