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/time.h" | 5 #include "base/time.h" |
6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
9 #include "chrome/common/chrome_notification_types.h" | |
9 #include "chrome/test/base/in_process_browser_test.h" | 10 #include "chrome/test/base/in_process_browser_test.h" |
10 #include "chrome/test/base/ui_test_utils.h" | 11 #include "chrome/test/base/ui_test_utils.h" |
11 #include "content/browser/renderer_host/render_view_host.h" | 12 #include "content/browser/renderer_host/render_view_host.h" |
12 #include "content/browser/tab_contents/tab_contents.h" | 13 #include "content/browser/tab_contents/tab_contents.h" |
13 #include "content/browser/tab_contents/tab_contents_observer.h" | 14 #include "content/browser/tab_contents/tab_contents_observer.h" |
14 #include "content/common/view_messages.h" | 15 #include "content/common/view_messages.h" |
15 #include "net/base/host_port_pair.h" | 16 #include "net/base/host_port_pair.h" |
16 #include "net/test/test_server.h" | 17 #include "net/test/test_server.h" |
17 | 18 |
18 typedef std::pair<int, Value*> ExecuteDetailType; | 19 typedef std::pair<int, Value*> ExecuteDetailType; |
(...skipping 24 matching lines...) Expand all Loading... | |
43 int id_; | 44 int id_; |
44 scoped_ptr<Value> value_; | 45 scoped_ptr<Value> value_; |
45 | 46 |
46 DISALLOW_COPY_AND_ASSIGN(ExecuteNotificationObserver); | 47 DISALLOW_COPY_AND_ASSIGN(ExecuteNotificationObserver); |
47 }; | 48 }; |
48 | 49 |
49 } // namespace | 50 } // namespace |
50 | 51 |
51 class RenderViewHostTest : public InProcessBrowserTest { | 52 class RenderViewHostTest : public InProcessBrowserTest { |
52 public: | 53 public: |
53 RenderViewHostTest() : last_execute_id_(0) {} | 54 RenderViewHostTest() : last_execute_id_(0) { |
55 EnableDOMAutomation(); | |
56 } | |
54 | 57 |
55 void ExecuteJavascriptAndGetValue(const char* script, | 58 void ExecuteJavascriptAndGetValue(const char* script, |
56 ExecuteNotificationObserver* out_result) { | 59 ExecuteNotificationObserver* out_result) { |
57 RenderViewHost* rvh = | 60 RenderViewHost* rvh = |
58 browser()->GetSelectedTabContents()->render_view_host(); | 61 browser()->GetSelectedTabContents()->render_view_host(); |
59 ASSERT_TRUE(rvh); | 62 ASSERT_TRUE(rvh); |
60 int execute_id = rvh->ExecuteJavascriptInWebFrameNotifyResult( | 63 int execute_id = rvh->ExecuteJavascriptInWebFrameNotifyResult( |
61 string16(), | 64 string16(), |
62 ASCIIToUTF16(script)); | 65 ASCIIToUTF16(script)); |
63 EXPECT_NE(execute_id, last_execute_id_); | 66 EXPECT_NE(execute_id, last_execute_id_); |
64 ExecuteNotificationObserver observer; | 67 ExecuteNotificationObserver observer; |
65 ui_test_utils::RegisterAndWait( | 68 ui_test_utils::RegisterAndWait( |
66 out_result, | 69 out_result, |
67 content::NOTIFICATION_EXECUTE_JAVASCRIPT_RESULT, | 70 content::NOTIFICATION_EXECUTE_JAVASCRIPT_RESULT, |
68 Source<RenderViewHost>(rvh)); | 71 Source<RenderViewHost>(rvh)); |
69 EXPECT_EQ(execute_id, out_result->id()); | 72 EXPECT_EQ(execute_id, out_result->id()); |
70 ASSERT_TRUE(out_result->value()); | 73 ASSERT_TRUE(out_result->value()); |
71 last_execute_id_ = execute_id; | 74 last_execute_id_ = execute_id; |
72 } | 75 } |
73 | 76 |
77 protected: | |
78 bool GetCreatedWindowName(const GURL& url, | |
79 const wchar_t* function, | |
80 std::string* window_name) { | |
81 ui_test_utils::NavigateToURL(browser(), url); | |
82 | |
83 if (!ui_test_utils::ExecuteJavaScriptAndExtractString( | |
84 browser()->GetSelectedTabContents()->render_view_host(), | |
darin (slow to review)
2011/08/30 20:32:30
nit: use 4 space indent for line continuation.
| |
85 L"", function, window_name)) | |
86 return false; | |
87 | |
88 return true; | |
89 } | |
90 | |
74 private: | 91 private: |
75 int last_execute_id_; | 92 int last_execute_id_; |
76 }; | 93 }; |
77 | 94 |
78 | 95 |
79 // Makes sure ExecuteJavascriptInWebFrameNotifyResult works. | 96 // Makes sure ExecuteJavascriptInWebFrameNotifyResult works. |
80 IN_PROC_BROWSER_TEST_F(RenderViewHostTest, | 97 IN_PROC_BROWSER_TEST_F(RenderViewHostTest, |
81 ExecuteJavascriptInWebFrameNotifyResult) { | 98 ExecuteJavascriptInWebFrameNotifyResult) { |
82 ASSERT_TRUE(test_server()->Start()); | 99 ASSERT_TRUE(test_server()->Start()); |
83 GURL empty_url(test_server()->GetURL("files/empty.html")); | 100 GURL empty_url(test_server()->GetURL("files/empty.html")); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
237 RenderViewHostTestTabContentsObserver observer( | 254 RenderViewHostTestTabContentsObserver observer( |
238 browser()->GetSelectedTabContents()); | 255 browser()->GetSelectedTabContents()); |
239 | 256 |
240 GURL test_url = test_server()->GetURL("files/simple.html"); | 257 GURL test_url = test_server()->GetURL("files/simple.html"); |
241 ui_test_utils::NavigateToURL(browser(), test_url); | 258 ui_test_utils::NavigateToURL(browser(), test_url); |
242 | 259 |
243 EXPECT_EQ(test_server()->host_port_pair().ToString(), | 260 EXPECT_EQ(test_server()->host_port_pair().ToString(), |
244 observer.observed_socket_address().ToString()); | 261 observer.observed_socket_address().ToString()); |
245 EXPECT_EQ(1, observer.navigation_count()); | 262 EXPECT_EQ(1, observer.navigation_count()); |
246 } | 263 } |
264 | |
265 // Regression test for http://crbug.com/88129 | |
266 IN_PROC_BROWSER_TEST_F(RenderViewHostTest, WindowOpen1) { | |
267 ASSERT_TRUE(test_server()->Start()); | |
268 | |
269 GURL url(test_server()->GetURL("files/window.open.blank.html")); | |
270 std::string window_name; | |
271 ASSERT_TRUE(GetCreatedWindowName(url, L"openWindow1();", &window_name)); | |
272 | |
273 EXPECT_EQ(window_name, "blank") << "Actual Window Name: " << window_name; | |
274 } | |
275 | |
276 // Regression test for http://crbug.com/88129 | |
277 IN_PROC_BROWSER_TEST_F(RenderViewHostTest, WindowOpen2) { | |
278 ASSERT_TRUE(test_server()->Start()); | |
279 | |
280 GURL url(test_server()->GetURL("files/window.open.blank.html")); | |
281 std::string window_name; | |
282 ASSERT_TRUE(GetCreatedWindowName(url, L"openWindow2();", &window_name)); | |
283 | |
284 EXPECT_EQ(window_name, "") << "Actual Window Name: " << window_name; | |
285 } | |
OLD | NEW |