OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/file_path.h" | 5 #include "base/file_path.h" |
6 #include "base/gfx/native_widget_types.h" | 6 #include "base/gfx/native_widget_types.h" |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/sys_info.h" | 8 #include "base/sys_info.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/app/chrome_dll_resource.h" | 10 #include "chrome/app/chrome_dll_resource.h" |
11 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
12 #include "chrome/common/chrome_constants.h" | 12 #include "chrome/common/chrome_constants.h" |
13 #include "chrome/common/platform_util.h" | 13 #include "chrome/common/platform_util.h" |
14 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
15 #include "chrome/test/automation/browser_proxy.h" | 15 #include "chrome/test/automation/browser_proxy.h" |
16 #include "chrome/test/automation/tab_proxy.h" | 16 #include "chrome/test/automation/tab_proxy.h" |
17 #include "chrome/test/automation/window_proxy.h" | 17 #include "chrome/test/automation/window_proxy.h" |
18 #include "chrome/test/ui/ui_test.h" | 18 #include "chrome/test/ui/ui_test.h" |
19 #include "net/base/net_util.h" | 19 #include "net/base/net_util.h" |
20 #include "net/url_request/url_request_unittest.h" | 20 #include "net/url_request/url_request_unittest.h" |
21 #include "grit/chromium_strings.h" | 21 #include "grit/chromium_strings.h" |
22 #include "grit/generated_resources.h" | 22 #include "grit/generated_resources.h" |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 class BrowserTest : public UITest { | 26 class BrowserTest : public UITest { |
27 protected: | |
28 #if defined(OS_WIN) | |
29 HWND GetMainWindow() { | |
30 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | |
31 scoped_refptr<WindowProxy> window(browser->GetWindow()); | |
32 | |
33 HWND window_handle; | |
34 EXPECT_TRUE(window->GetHWND(&window_handle)); | |
35 return window_handle; | |
36 } | |
37 #endif | |
38 }; | 27 }; |
39 | 28 |
40 class VisibleBrowserTest : public UITest { | 29 class VisibleBrowserTest : public UITest { |
41 protected: | 30 protected: |
42 VisibleBrowserTest() : UITest() { | 31 VisibleBrowserTest() : UITest() { |
43 show_window_ = true; | 32 show_window_ = true; |
44 } | 33 } |
45 }; | 34 }; |
46 | 35 |
47 #if defined(OS_WIN) | 36 #if defined(OS_WIN) |
48 // The browser should quit quickly if it receives a WM_ENDSESSION message. | 37 // The browser should quit quickly if it receives a WM_ENDSESSION message. |
49 TEST_F(BrowserTest, WindowsSessionEnd) { | 38 TEST_F(BrowserTest, WindowsSessionEnd) { |
50 FilePath test_file(test_data_directory_); | 39 FilePath test_file(test_data_directory_); |
51 test_file = test_file.AppendASCII("title1.html"); | 40 test_file = test_file.AppendASCII("title1.html"); |
52 | 41 |
53 NavigateToURL(net::FilePathToFileURL(test_file)); | 42 NavigateToURL(net::FilePathToFileURL(test_file)); |
54 PlatformThread::Sleep(action_timeout_ms()); | 43 PlatformThread::Sleep(action_timeout_ms()); |
55 | 44 |
56 // Simulate an end of session. Normally this happens when the user | 45 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
57 // shuts down the pc or logs off. | 46 ASSERT_TRUE(browser->TerminateSession()); |
58 HWND window_handle = GetMainWindow(); | |
59 ASSERT_TRUE(::PostMessageW(window_handle, WM_ENDSESSION, 0, 0)); | |
60 | 47 |
61 PlatformThread::Sleep(action_timeout_ms()); | 48 PlatformThread::Sleep(action_timeout_ms()); |
62 ASSERT_FALSE(IsBrowserRunning()); | 49 ASSERT_FALSE(IsBrowserRunning()); |
63 | 50 |
64 // Make sure the UMA metrics say we didn't crash. | 51 // Make sure the UMA metrics say we didn't crash. |
65 scoped_ptr<DictionaryValue> local_prefs(GetLocalState()); | 52 scoped_ptr<DictionaryValue> local_prefs(GetLocalState()); |
66 bool exited_cleanly; | 53 bool exited_cleanly; |
67 ASSERT_TRUE(local_prefs.get()); | 54 ASSERT_TRUE(local_prefs.get()); |
68 ASSERT_TRUE(local_prefs->GetBoolean(prefs::kStabilityExitedCleanly, | 55 ASSERT_TRUE(local_prefs->GetBoolean(prefs::kStabilityExitedCleanly, |
69 &exited_cleanly)); | 56 &exited_cleanly)); |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 | 238 |
252 GURL url = net::FilePathToFileURL(test_file); | 239 GURL url = net::FilePathToFileURL(test_file); |
253 ASSERT_TRUE(tab->NavigateToURL(url)); | 240 ASSERT_TRUE(tab->NavigateToURL(url)); |
254 | 241 |
255 std::string value = WaitUntilCookieNonEmpty(tab.get(), url, | 242 std::string value = WaitUntilCookieNonEmpty(tab.get(), url, |
256 "status", kTestIntervalMs, kTestWaitTimeoutMs); | 243 "status", kTestIntervalMs, kTestWaitTimeoutMs); |
257 ASSERT_STREQ("Disallowed", value.c_str()); | 244 ASSERT_STREQ("Disallowed", value.c_str()); |
258 } | 245 } |
259 | 246 |
260 } // namespace | 247 } // namespace |
OLD | NEW |