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

Side by Side Diff: chrome/browser/geolocation/geolocation_browsertest.cc

Issue 7327007: Moving notification types which are chrome specific to a new header file chrome_notification_type... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 months 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 "base/compiler_specific.h" 5 #include "base/compiler_specific.h"
6 #include "base/stringprintf.h" 6 #include "base/stringprintf.h"
7 #include "base/string_number_conversions.h" 7 #include "base/string_number_conversions.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 9 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
10 #include "chrome/browser/dom_operation_notification_details.h" 10 #include "chrome/browser/dom_operation_notification_details.h"
11 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" 11 #include "chrome/browser/geolocation/geolocation_content_settings_map.h"
12 #include "chrome/browser/geolocation/geolocation_settings_state.h" 12 #include "chrome/browser/geolocation/geolocation_settings_state.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" 14 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h"
15 #include "chrome/browser/tab_contents/infobar.h" 15 #include "chrome/browser/tab_contents/infobar.h"
16 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_list.h" 17 #include "chrome/browser/ui/browser_list.h"
18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
19 #include "chrome/common/chrome_notification_types.h"
19 #include "chrome/common/chrome_paths.h" 20 #include "chrome/common/chrome_paths.h"
20 #include "chrome/test/in_process_browser_test.h" 21 #include "chrome/test/in_process_browser_test.h"
21 #include "chrome/test/ui_test_utils.h" 22 #include "chrome/test/ui_test_utils.h"
22 #include "content/browser/geolocation/arbitrator_dependency_factories_for_test.h " 23 #include "content/browser/geolocation/arbitrator_dependency_factories_for_test.h "
23 #include "content/browser/geolocation/location_arbitrator.h" 24 #include "content/browser/geolocation/location_arbitrator.h"
24 #include "content/browser/geolocation/mock_location_provider.h" 25 #include "content/browser/geolocation/mock_location_provider.h"
25 #include "content/browser/renderer_host/render_view_host.h" 26 #include "content/browser/renderer_host/render_view_host.h"
26 #include "content/browser/tab_contents/tab_contents.h" 27 #include "content/browser/tab_contents/tab_contents.h"
27 #include "content/common/geoposition.h" 28 #include "content/common/geoposition.h"
28 #include "content/common/notification_details.h" 29 #include "content/common/notification_details.h"
29 #include "content/common/notification_service.h" 30 #include "content/common/notification_service.h"
30 #include "content/common/notification_type.h"
31 #include "net/base/net_util.h" 31 #include "net/base/net_util.h"
32 #include "net/test/test_server.h" 32 #include "net/test/test_server.h"
33 33
34 namespace { 34 namespace {
35 35
36 // Used to block until an iframe is loaded via a javascript call. 36 // Used to block until an iframe is loaded via a javascript call.
37 // Note: NavigateToURLBlockUntilNavigationsComplete doesn't seem to work for 37 // Note: NavigateToURLBlockUntilNavigationsComplete doesn't seem to work for
38 // multiple embedded iframes, as notifications seem to be 'batched'. Instead, we 38 // multiple embedded iframes, as notifications seem to be 'batched'. Instead, we
39 // load and wait one single frame here by calling a javascript function. 39 // load and wait one single frame here by calling a javascript function.
40 class IFrameLoader : public NotificationObserver { 40 class IFrameLoader : public NotificationObserver {
41 public: 41 public:
42 IFrameLoader(Browser* browser, int iframe_id, const GURL& url) 42 IFrameLoader(Browser* browser, int iframe_id, const GURL& url)
43 : navigation_completed_(false), 43 : navigation_completed_(false),
44 javascript_completed_(false) { 44 javascript_completed_(false) {
45 NavigationController* controller = 45 NavigationController* controller =
46 &browser->GetSelectedTabContents()->controller(); 46 &browser->GetSelectedTabContents()->controller();
47 registrar_.Add(this, NotificationType::LOAD_STOP, 47 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP,
48 Source<NavigationController>(controller)); 48 Source<NavigationController>(controller));
49 registrar_.Add(this, NotificationType::DOM_OPERATION_RESPONSE, 49 registrar_.Add(this, chrome::NOTIFICATION_DOM_OPERATION_RESPONSE,
50 NotificationService::AllSources()); 50 NotificationService::AllSources());
51 std::string script = base::StringPrintf( 51 std::string script = base::StringPrintf(
52 "window.domAutomationController.setAutomationId(0);" 52 "window.domAutomationController.setAutomationId(0);"
53 "window.domAutomationController.send(addIFrame(%d, \"%s\"));", 53 "window.domAutomationController.send(addIFrame(%d, \"%s\"));",
54 iframe_id, 54 iframe_id,
55 url.spec().c_str()); 55 url.spec().c_str());
56 browser->GetSelectedTabContents()->render_view_host()-> 56 browser->GetSelectedTabContents()->render_view_host()->
57 ExecuteJavascriptInWebFrame(string16(), UTF8ToUTF16(script)); 57 ExecuteJavascriptInWebFrame(string16(), UTF8ToUTF16(script));
58 ui_test_utils::RunMessageLoop(); 58 ui_test_utils::RunMessageLoop();
59 59
60 EXPECT_EQ(base::StringPrintf("\"%d\"", iframe_id), javascript_response_); 60 EXPECT_EQ(base::StringPrintf("\"%d\"", iframe_id), javascript_response_);
61 registrar_.RemoveAll(); 61 registrar_.RemoveAll();
62 // Now that we loaded the iframe, let's fetch its src. 62 // Now that we loaded the iframe, let's fetch its src.
63 script = base::StringPrintf( 63 script = base::StringPrintf(
64 "window.domAutomationController.send(getIFrameSrc(%d))", iframe_id); 64 "window.domAutomationController.send(getIFrameSrc(%d))", iframe_id);
65 std::string iframe_src; 65 std::string iframe_src;
66 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( 66 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString(
67 browser->GetSelectedTabContents()->render_view_host(), 67 browser->GetSelectedTabContents()->render_view_host(),
68 L"", UTF8ToWide(script), &iframe_src)); 68 L"", UTF8ToWide(script), &iframe_src));
69 iframe_url_ = GURL(iframe_src); 69 iframe_url_ = GURL(iframe_src);
70 } 70 }
71 71
72 GURL iframe_url() const { return iframe_url_; } 72 GURL iframe_url() const { return iframe_url_; }
73 73
74 virtual void Observe(NotificationType type, 74 virtual void Observe(int type,
75 const NotificationSource& source, 75 const NotificationSource& source,
76 const NotificationDetails& details) { 76 const NotificationDetails& details) {
77 if (type == NotificationType::LOAD_STOP) { 77 if (type == content::NOTIFICATION_LOAD_STOP) {
78 navigation_completed_ = true; 78 navigation_completed_ = true;
79 } else if (type == NotificationType::DOM_OPERATION_RESPONSE) { 79 } else if (type == chrome::NOTIFICATION_DOM_OPERATION_RESPONSE) {
80 Details<DomOperationNotificationDetails> dom_op_details(details); 80 Details<DomOperationNotificationDetails> dom_op_details(details);
81 javascript_response_ = dom_op_details->json(); 81 javascript_response_ = dom_op_details->json();
82 javascript_completed_ = true; 82 javascript_completed_ = true;
83 } 83 }
84 if (javascript_completed_ && navigation_completed_) 84 if (javascript_completed_ && navigation_completed_)
85 MessageLoopForUI::current()->Quit(); 85 MessageLoopForUI::current()->Quit();
86 } 86 }
87 87
88 private: 88 private:
89 NotificationRegistrar registrar_; 89 NotificationRegistrar registrar_;
(...skipping 15 matching lines...) Expand all
105 class GeolocationNotificationObserver : public NotificationObserver { 105 class GeolocationNotificationObserver : public NotificationObserver {
106 public: 106 public:
107 // If |wait_for_infobar| is true, AddWatchAndWaitForNotification will block 107 // If |wait_for_infobar| is true, AddWatchAndWaitForNotification will block
108 // until the infobar has been displayed; otherwise it will block until the 108 // until the infobar has been displayed; otherwise it will block until the
109 // navigation is completed. 109 // navigation is completed.
110 explicit GeolocationNotificationObserver(bool wait_for_infobar) 110 explicit GeolocationNotificationObserver(bool wait_for_infobar)
111 : wait_for_infobar_(wait_for_infobar), 111 : wait_for_infobar_(wait_for_infobar),
112 infobar_(NULL), 112 infobar_(NULL),
113 navigation_started_(false), 113 navigation_started_(false),
114 navigation_completed_(false) { 114 navigation_completed_(false) {
115 registrar_.Add(this, NotificationType::DOM_OPERATION_RESPONSE, 115 registrar_.Add(this, chrome::NOTIFICATION_DOM_OPERATION_RESPONSE,
116 NotificationService::AllSources()); 116 NotificationService::AllSources());
117 if (wait_for_infobar) { 117 if (wait_for_infobar) {
118 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_ADDED, 118 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED,
119 NotificationService::AllSources()); 119 NotificationService::AllSources());
120 } else { 120 } else {
121 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, 121 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
122 NotificationService::AllSources()); 122 NotificationService::AllSources());
123 registrar_.Add(this, NotificationType::LOAD_START, 123 registrar_.Add(this, content::NOTIFICATION_LOAD_START,
124 NotificationService::AllSources()); 124 NotificationService::AllSources());
125 registrar_.Add(this, NotificationType::LOAD_STOP, 125 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP,
126 NotificationService::AllSources()); 126 NotificationService::AllSources());
127 } 127 }
128 } 128 }
129 129
130 void AddWatchAndWaitForNotification(RenderViewHost* render_view_host, 130 void AddWatchAndWaitForNotification(RenderViewHost* render_view_host,
131 const std::wstring& iframe_xpath) { 131 const std::wstring& iframe_xpath) {
132 LOG(WARNING) << "will add geolocation watch"; 132 LOG(WARNING) << "will add geolocation watch";
133 std::string script = 133 std::string script =
134 "window.domAutomationController.setAutomationId(0);" 134 "window.domAutomationController.setAutomationId(0);"
135 "window.domAutomationController.send(geoStart());"; 135 "window.domAutomationController.send(geoStart());";
136 render_view_host->ExecuteJavascriptInWebFrame(WideToUTF16Hack(iframe_xpath), 136 render_view_host->ExecuteJavascriptInWebFrame(WideToUTF16Hack(iframe_xpath),
137 UTF8ToUTF16(script)); 137 UTF8ToUTF16(script));
138 ui_test_utils::RunMessageLoop(); 138 ui_test_utils::RunMessageLoop();
139 registrar_.RemoveAll(); 139 registrar_.RemoveAll();
140 LOG(WARNING) << "got geolocation watch" << javascript_response_; 140 LOG(WARNING) << "got geolocation watch" << javascript_response_;
141 EXPECT_NE("\"0\"", javascript_response_); 141 EXPECT_NE("\"0\"", javascript_response_);
142 if (wait_for_infobar_) { 142 if (wait_for_infobar_) {
143 EXPECT_TRUE(infobar_); 143 EXPECT_TRUE(infobar_);
144 } else { 144 } else {
145 EXPECT_TRUE(navigation_completed_); 145 EXPECT_TRUE(navigation_completed_);
146 } 146 }
147 } 147 }
148 148
149 // NotificationObserver 149 // NotificationObserver
150 virtual void Observe(NotificationType type, 150 virtual void Observe(int type,
151 const NotificationSource& source, 151 const NotificationSource& source,
152 const NotificationDetails& details) { 152 const NotificationDetails& details) {
153 if (type.value == NotificationType::TAB_CONTENTS_INFOBAR_ADDED) { 153 if (type == chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED) {
154 infobar_ = Details<InfoBarAddedDetails>(details).ptr(); 154 infobar_ = Details<InfoBarAddedDetails>(details).ptr();
155 ASSERT_TRUE(infobar_->GetIcon()); 155 ASSERT_TRUE(infobar_->GetIcon());
156 ASSERT_TRUE(infobar_->AsConfirmInfoBarDelegate()); 156 ASSERT_TRUE(infobar_->AsConfirmInfoBarDelegate());
157 } else if (type == NotificationType::DOM_OPERATION_RESPONSE) { 157 } else if (type == chrome::NOTIFICATION_DOM_OPERATION_RESPONSE) {
158 Details<DomOperationNotificationDetails> dom_op_details(details); 158 Details<DomOperationNotificationDetails> dom_op_details(details);
159 javascript_response_ = dom_op_details->json(); 159 javascript_response_ = dom_op_details->json();
160 LOG(WARNING) << "javascript_response " << javascript_response_; 160 LOG(WARNING) << "javascript_response " << javascript_response_;
161 } else if (type == NotificationType::NAV_ENTRY_COMMITTED || 161 } else if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED ||
162 type == NotificationType::LOAD_START) { 162 type == content::NOTIFICATION_LOAD_START) {
163 navigation_started_ = true; 163 navigation_started_ = true;
164 } else if (type == NotificationType::LOAD_STOP) { 164 } else if (type == content::NOTIFICATION_LOAD_STOP) {
165 if (navigation_started_) { 165 if (navigation_started_) {
166 navigation_started_ = false; 166 navigation_started_ = false;
167 navigation_completed_ = true; 167 navigation_completed_ = true;
168 } 168 }
169 } 169 }
170 170
171 // We're either waiting for just the inforbar, or for both a javascript 171 // We're either waiting for just the inforbar, or for both a javascript
172 // prompt and response. 172 // prompt and response.
173 if (wait_for_infobar_ && infobar_) 173 if (wait_for_infobar_ && infobar_)
174 MessageLoopForUI::current()->Quit(); 174 MessageLoopForUI::current()->Quit();
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 "window.domAutomationController.setAutomationId(0);" 645 "window.domAutomationController.setAutomationId(0);"
646 "window.domAutomationController.send(window.close());"; 646 "window.domAutomationController.send(window.close());";
647 bool result = 647 bool result =
648 ui_test_utils::ExecuteJavaScript( 648 ui_test_utils::ExecuteJavaScript(
649 current_browser_->GetSelectedTabContents()->render_view_host(), 649 current_browser_->GetSelectedTabContents()->render_view_host(),
650 L"", UTF8ToWide(script)); 650 L"", UTF8ToWide(script));
651 EXPECT_EQ(result, true); 651 EXPECT_EQ(result, true);
652 } 652 }
653 653
654 } // namespace 654 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698