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/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/test/in_process_browser_test.h" | 10 #include "chrome/test/in_process_browser_test.h" |
11 #include "chrome/test/ui_test_utils.h" | 11 #include "chrome/test/ui_test_utils.h" |
12 #include "content/browser/renderer_host/render_view_host.h" | 12 #include "content/browser/renderer_host/render_view_host.h" |
13 #include "content/browser/tab_contents/tab_contents.h" | 13 #include "content/browser/tab_contents/tab_contents.h" |
14 #include "content/browser/tab_contents/tab_contents_observer.h" | 14 #include "content/browser/tab_contents/tab_contents_observer.h" |
15 #include "content/common/view_messages.h" | 15 #include "content/common/view_messages.h" |
16 #include "net/base/host_port_pair.h" | 16 #include "net/base/host_port_pair.h" |
17 #include "net/test/test_server.h" | 17 #include "net/test/test_server.h" |
18 | 18 |
19 typedef std::pair<int, Value*> ExecuteDetailType; | 19 typedef std::pair<int, Value*> ExecuteDetailType; |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 // NotificationObserver used to listen for EXECUTE_JAVASCRIPT_RESULT | 23 // NotificationObserver used to listen for EXECUTE_JAVASCRIPT_RESULT |
24 // notifications. | 24 // notifications. |
25 class ExecuteNotificationObserver : public NotificationObserver { | 25 class ExecuteNotificationObserver : public NotificationObserver { |
26 public: | 26 public: |
27 ExecuteNotificationObserver() : id_(0) {} | 27 ExecuteNotificationObserver() : id_(0) {} |
28 | 28 |
29 virtual void Observe(NotificationType type, | 29 virtual void Observe(int type, |
30 const NotificationSource& source, | 30 const NotificationSource& source, |
31 const NotificationDetails& details) { | 31 const NotificationDetails& details) { |
32 id_ = (static_cast<Details<ExecuteDetailType > >(details))->first; | 32 id_ = (static_cast<Details<ExecuteDetailType > >(details))->first; |
33 Value* value = (static_cast<Details<ExecuteDetailType > >(details))->second; | 33 Value* value = (static_cast<Details<ExecuteDetailType > >(details))->second; |
34 if (value) | 34 if (value) |
35 value_.reset(value->DeepCopy()); | 35 value_.reset(value->DeepCopy()); |
36 MessageLoopForUI::current()->Quit(); | 36 MessageLoopForUI::current()->Quit(); |
37 } | 37 } |
38 | 38 |
39 int id() const { return id_; } | 39 int id() const { return id_; } |
(...skipping 18 matching lines...) Expand all Loading... |
58 RenderViewHost* rvh = | 58 RenderViewHost* rvh = |
59 browser()->GetSelectedTabContents()->render_view_host(); | 59 browser()->GetSelectedTabContents()->render_view_host(); |
60 ASSERT_TRUE(rvh); | 60 ASSERT_TRUE(rvh); |
61 int execute_id = rvh->ExecuteJavascriptInWebFrameNotifyResult( | 61 int execute_id = rvh->ExecuteJavascriptInWebFrameNotifyResult( |
62 string16(), | 62 string16(), |
63 ASCIIToUTF16(script)); | 63 ASCIIToUTF16(script)); |
64 EXPECT_NE(execute_id, last_execute_id_); | 64 EXPECT_NE(execute_id, last_execute_id_); |
65 ExecuteNotificationObserver observer; | 65 ExecuteNotificationObserver observer; |
66 ui_test_utils::RegisterAndWait( | 66 ui_test_utils::RegisterAndWait( |
67 out_result, | 67 out_result, |
68 NotificationType::EXECUTE_JAVASCRIPT_RESULT, | 68 content::NOTIFICATION_EXECUTE_JAVASCRIPT_RESULT, |
69 Source<RenderViewHost>(rvh)); | 69 Source<RenderViewHost>(rvh)); |
70 EXPECT_EQ(execute_id, out_result->id()); | 70 EXPECT_EQ(execute_id, out_result->id()); |
71 ASSERT_TRUE(out_result->value()); | 71 ASSERT_TRUE(out_result->value()); |
72 last_execute_id_ = execute_id; | 72 last_execute_id_ = execute_id; |
73 } | 73 } |
74 | 74 |
75 private: | 75 private: |
76 int last_execute_id_; | 76 int last_execute_id_; |
77 }; | 77 }; |
78 | 78 |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 RenderViewHostTestTabContentsObserver observer( | 238 RenderViewHostTestTabContentsObserver observer( |
239 browser()->GetSelectedTabContents()); | 239 browser()->GetSelectedTabContents()); |
240 | 240 |
241 GURL test_url = test_server()->GetURL("files/simple.html"); | 241 GURL test_url = test_server()->GetURL("files/simple.html"); |
242 ui_test_utils::NavigateToURL(browser(), test_url); | 242 ui_test_utils::NavigateToURL(browser(), test_url); |
243 | 243 |
244 EXPECT_EQ(test_server()->host_port_pair().ToString(), | 244 EXPECT_EQ(test_server()->host_port_pair().ToString(), |
245 observer.observed_socket_address().ToString()); | 245 observer.observed_socket_address().ToString()); |
246 EXPECT_EQ(1, observer.navigation_count()); | 246 EXPECT_EQ(1, observer.navigation_count()); |
247 } | 247 } |
OLD | NEW |