OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 | 134 |
135 // content::NotificationObserver: | 135 // content::NotificationObserver: |
136 virtual void Observe(int type, | 136 virtual void Observe(int type, |
137 const content::NotificationSource& source, | 137 const content::NotificationSource& source, |
138 const content::NotificationDetails& details) OVERRIDE; | 138 const content::NotificationDetails& details) OVERRIDE; |
139 | 139 |
140 void AddWatchAndWaitForNotification(content::RenderViewHost* render_view_host, | 140 void AddWatchAndWaitForNotification(content::RenderViewHost* render_view_host, |
141 const std::string& iframe_xpath); | 141 const std::string& iframe_xpath); |
142 | 142 |
143 bool has_infobar() const { return !!infobar_; } | 143 bool has_infobar() const { return !!infobar_; } |
144 InfoBar* infobar() { return infobar_; } | 144 InfoBarDelegate* infobar() { return infobar_; } |
145 | 145 |
146 private: | 146 private: |
147 content::NotificationRegistrar registrar_; | 147 content::NotificationRegistrar registrar_; |
148 bool wait_for_infobar_; | 148 bool wait_for_infobar_; |
149 InfoBar* infobar_; | 149 InfoBarDelegate* infobar_; |
150 bool navigation_started_; | 150 bool navigation_started_; |
151 bool navigation_completed_; | 151 bool navigation_completed_; |
152 std::string javascript_response_; | 152 std::string javascript_response_; |
153 | 153 |
154 DISALLOW_COPY_AND_ASSIGN(GeolocationNotificationObserver); | 154 DISALLOW_COPY_AND_ASSIGN(GeolocationNotificationObserver); |
155 }; | 155 }; |
156 | 156 |
157 GeolocationNotificationObserver::GeolocationNotificationObserver( | 157 GeolocationNotificationObserver::GeolocationNotificationObserver( |
158 bool wait_for_infobar) | 158 bool wait_for_infobar) |
159 : wait_for_infobar_(wait_for_infobar), | 159 : wait_for_infobar_(wait_for_infobar), |
(...skipping 17 matching lines...) Expand all Loading... |
177 | 177 |
178 GeolocationNotificationObserver::~GeolocationNotificationObserver() { | 178 GeolocationNotificationObserver::~GeolocationNotificationObserver() { |
179 } | 179 } |
180 | 180 |
181 void GeolocationNotificationObserver::Observe( | 181 void GeolocationNotificationObserver::Observe( |
182 int type, | 182 int type, |
183 const content::NotificationSource& source, | 183 const content::NotificationSource& source, |
184 const content::NotificationDetails& details) { | 184 const content::NotificationDetails& details) { |
185 if (type == chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED) { | 185 if (type == chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED) { |
186 infobar_ = content::Details<InfoBar::AddedDetails>(details).ptr(); | 186 infobar_ = content::Details<InfoBar::AddedDetails>(details).ptr(); |
187 ASSERT_FALSE(infobar_->delegate()->GetIcon().IsEmpty()); | 187 ASSERT_FALSE(infobar_->GetIcon().IsEmpty()); |
188 ASSERT_TRUE(infobar_->delegate()->AsConfirmInfoBarDelegate()); | 188 ASSERT_TRUE(infobar_->AsConfirmInfoBarDelegate()); |
189 } else if (type == content::NOTIFICATION_DOM_OPERATION_RESPONSE) { | 189 } else if (type == content::NOTIFICATION_DOM_OPERATION_RESPONSE) { |
190 content::Details<DomOperationNotificationDetails> dom_op_details(details); | 190 content::Details<DomOperationNotificationDetails> dom_op_details(details); |
191 javascript_response_ = dom_op_details->json; | 191 javascript_response_ = dom_op_details->json; |
192 LOG(WARNING) << "javascript_response " << javascript_response_; | 192 LOG(WARNING) << "javascript_response " << javascript_response_; |
193 } else if ((type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) || | 193 } else if ((type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) || |
194 (type == content::NOTIFICATION_LOAD_START)) { | 194 (type == content::NOTIFICATION_LOAD_START)) { |
195 navigation_started_ = true; | 195 navigation_started_ = true; |
196 } else if ((type == content::NOTIFICATION_LOAD_STOP) && navigation_started_) { | 196 } else if ((type == content::NOTIFICATION_LOAD_STOP) && navigation_started_) { |
197 navigation_started_ = false; | 197 navigation_started_ = false; |
198 navigation_completed_ = true; | 198 navigation_completed_ = true; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 WebContents* web_contents); | 291 WebContents* web_contents); |
292 | 292 |
293 // Executes |function| and checks that the return value matches |expected|. | 293 // Executes |function| and checks that the return value matches |expected|. |
294 void CheckStringValueFromJavascript(const std::string& expected, | 294 void CheckStringValueFromJavascript(const std::string& expected, |
295 const std::string& function); | 295 const std::string& function); |
296 | 296 |
297 // Sets a new position and sends a notification with the new position. | 297 // Sets a new position and sends a notification with the new position. |
298 void NotifyGeoposition(double latitude, double longitude); | 298 void NotifyGeoposition(double latitude, double longitude); |
299 | 299 |
300 private: | 300 private: |
301 InfoBar* infobar_; | 301 InfoBarDelegate* infobar_; |
302 Browser* current_browser_; | 302 Browser* current_browser_; |
303 // path element of a URL referencing the html content for this test. | 303 // path element of a URL referencing the html content for this test. |
304 std::string html_for_tests_; | 304 std::string html_for_tests_; |
305 // This member defines the iframe (or top-level page, if empty) where the | 305 // This member defines the iframe (or top-level page, if empty) where the |
306 // javascript calls will run. | 306 // javascript calls will run. |
307 std::string iframe_xpath_; | 307 std::string iframe_xpath_; |
308 // The current url for the top level page. | 308 // The current url for the top level page. |
309 GURL current_url_; | 309 GURL current_url_; |
310 // If not empty, the GURLs for the iframes loaded by LoadIFrames(). | 310 // If not empty, the GURLs for the iframes loaded by LoadIFrames(). |
311 std::vector<GURL> iframe_urls_; | 311 std::vector<GURL> iframe_urls_; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 const ContentSettingsUsagesState& usages_state = | 400 const ContentSettingsUsagesState& usages_state = |
401 content_settings->geolocation_usages_state(); | 401 content_settings->geolocation_usages_state(); |
402 size_t state_map_size = usages_state.state_map().size(); | 402 size_t state_map_size = usages_state.state_map().size(); |
403 ASSERT_TRUE(infobar_); | 403 ASSERT_TRUE(infobar_); |
404 LOG(WARNING) << "will set infobar response"; | 404 LOG(WARNING) << "will set infobar response"; |
405 { | 405 { |
406 content::WindowedNotificationObserver observer( | 406 content::WindowedNotificationObserver observer( |
407 content::NOTIFICATION_LOAD_STOP, | 407 content::NOTIFICATION_LOAD_STOP, |
408 content::Source<NavigationController>(&web_contents->GetController())); | 408 content::Source<NavigationController>(&web_contents->GetController())); |
409 if (allowed) | 409 if (allowed) |
410 infobar_->delegate()->AsConfirmInfoBarDelegate()->Accept(); | 410 infobar_->AsConfirmInfoBarDelegate()->Accept(); |
411 else | 411 else |
412 infobar_->delegate()->AsConfirmInfoBarDelegate()->Cancel(); | 412 infobar_->AsConfirmInfoBarDelegate()->Cancel(); |
413 observer.Wait(); | 413 observer.Wait(); |
414 } | 414 } |
415 | 415 |
416 InfoBarService::FromWebContents(web_contents)->RemoveInfoBar(infobar_); | 416 InfoBarService::FromWebContents(web_contents)->RemoveInfoBar(infobar_); |
417 LOG(WARNING) << "infobar response set"; | 417 LOG(WARNING) << "infobar response set"; |
418 infobar_ = NULL; | 418 infobar_ = NULL; |
419 EXPECT_GT(usages_state.state_map().size(), state_map_size); | 419 EXPECT_GT(usages_state.state_map().size(), state_map_size); |
420 GURL requesting_origin(requesting_url.GetOrigin()); | 420 GURL requesting_origin(requesting_url.GetOrigin()); |
421 EXPECT_EQ(1U, usages_state.state_map().count(requesting_origin)); | 421 EXPECT_EQ(1U, usages_state.state_map().count(requesting_origin)); |
422 ContentSetting expected_setting = | 422 ContentSetting expected_setting = |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 | 737 |
738 set_iframe_xpath("//iframe[@id='iframe_2']"); | 738 set_iframe_xpath("//iframe[@id='iframe_2']"); |
739 AddGeolocationWatch(false); | 739 AddGeolocationWatch(false); |
740 | 740 |
741 std::string script = | 741 std::string script = |
742 "window.domAutomationController.send(window.close());"; | 742 "window.domAutomationController.send(window.close());"; |
743 bool result = content::ExecuteScript( | 743 bool result = content::ExecuteScript( |
744 current_browser()->tab_strip_model()->GetActiveWebContents(), script); | 744 current_browser()->tab_strip_model()->GetActiveWebContents(), script); |
745 EXPECT_EQ(result, true); | 745 EXPECT_EQ(result, true); |
746 } | 746 } |
OLD | NEW |