Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(948)

Side by Side Diff: chrome/browser/browser_focus_uitest.cc

Issue 8418034: Make string_util::WriteInto() DCHECK() that the supplied |length_with_null| > 1, meaning that the... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/format_macros.h" 8 #include "base/format_macros.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 const char kTypicalPageName[] = "typical_page.html"; 83 const char kTypicalPageName[] = "typical_page.html";
84 84
85 // Test to make sure Chrome is in the foreground as we start testing. This is 85 // Test to make sure Chrome is in the foreground as we start testing. This is
86 // required for tests that synthesize input to the Chrome window. 86 // required for tests that synthesize input to the Chrome window.
87 bool ChromeInForeground() { 87 bool ChromeInForeground() {
88 #if defined(OS_WIN) 88 #if defined(OS_WIN)
89 HWND window = ::GetForegroundWindow(); 89 HWND window = ::GetForegroundWindow();
90 std::wstring caption; 90 std::wstring caption;
91 std::wstring filename; 91 std::wstring filename;
92 int len = ::GetWindowTextLength(window) + 1; 92 int len = ::GetWindowTextLength(window) + 1;
93 ::GetWindowText(window, WriteInto(&caption, len), len); 93 if (len > 1)
94 ::GetWindowText(window, WriteInto(&caption, len), len);
94 bool chrome_window_in_foreground = 95 bool chrome_window_in_foreground =
95 EndsWith(caption, L" - Google Chrome", true) || 96 EndsWith(caption, L" - Google Chrome", true) ||
96 EndsWith(caption, L" - Chromium", true); 97 EndsWith(caption, L" - Chromium", true);
97 if (!chrome_window_in_foreground) { 98 if (!chrome_window_in_foreground) {
98 DWORD process_id; 99 DWORD process_id;
99 int thread_id = ::GetWindowThreadProcessId(window, &process_id); 100 int thread_id = ::GetWindowThreadProcessId(window, &process_id);
100 101
101 base::ProcessHandle process; 102 base::ProcessHandle process;
102 if (base::OpenProcessHandleWithAccess(process_id, 103 if (base::OpenProcessHandleWithAccess(process_id,
103 PROCESS_QUERY_LIMITED_INFORMATION, 104 PROCESS_QUERY_LIMITED_INFORMATION,
104 &process)) { 105 &process)) {
105 len = MAX_PATH; 106 if (!GetProcessImageFileName(process, WriteInto(&filename, MAX_PATH),
106 if (!GetProcessImageFileName(process, WriteInto(&filename, len), len)) { 107 MAX_PATH)) {
107 int error = GetLastError(); 108 int error = GetLastError();
108 filename = std::wstring(L"Unable to read filename for process id '" + 109 filename = std::wstring(L"Unable to read filename for process id '" +
109 base::IntToString16(process_id) + 110 base::IntToString16(process_id) +
110 L"' (error ") + 111 L"' (error ") +
111 base::IntToString16(error) + L")"; 112 base::IntToString16(error) + L")";
112 } 113 }
113 base::CloseProcessHandle(process); 114 base::CloseProcessHandle(process);
114 } 115 }
115 } 116 }
116 EXPECT_TRUE(chrome_window_in_foreground) 117 EXPECT_TRUE(chrome_window_in_foreground)
(...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 browser()->Reload(CURRENT_TAB); 905 browser()->Reload(CURRENT_TAB);
905 observer.Wait(); 906 observer.Wait();
906 } 907 }
907 908
908 // Focus should now be on the tab contents. 909 // Focus should now be on the tab contents.
909 browser()->ShowDownloadsTab(); 910 browser()->ShowDownloadsTab();
910 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); 911 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
911 } 912 }
912 913
913 } // namespace 914 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/automation/testing_automation_provider_win.cc ('k') | chrome/browser/mac/install_from_dmg.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698