| 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" |
| 11 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
| 12 #include "chrome/browser/content_settings/content_settings_usages_state.h" |
| 12 #include "chrome/browser/content_settings/host_content_settings_map.h" | 13 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 13 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 14 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 14 #include "chrome/browser/geolocation/geolocation_settings_state.h" | |
| 15 #include "chrome/browser/infobars/confirm_infobar_delegate.h" | 15 #include "chrome/browser/infobars/confirm_infobar_delegate.h" |
| 16 #include "chrome/browser/infobars/infobar.h" | 16 #include "chrome/browser/infobars/infobar.h" |
| 17 #include "chrome/browser/infobars/infobar_service.h" | 17 #include "chrome/browser/infobars/infobar_service.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
| 20 #include "chrome/browser/ui/browser_commands.h" | 20 #include "chrome/browser/ui/browser_commands.h" |
| 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 22 #include "chrome/common/chrome_paths.h" | 22 #include "chrome/common/chrome_paths.h" |
| 23 #include "chrome/common/content_settings_pattern.h" | 23 #include "chrome/common/content_settings_pattern.h" |
| 24 #include "chrome/test/base/in_process_browser_test.h" | 24 #include "chrome/test/base/in_process_browser_test.h" |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 CheckStringValueFromJavascript(base::DoubleToString(longitude), | 369 CheckStringValueFromJavascript(base::DoubleToString(longitude), |
| 370 "geoGetLastPositionLongitude()"); | 370 "geoGetLastPositionLongitude()"); |
| 371 } | 371 } |
| 372 | 372 |
| 373 void GeolocationBrowserTest::SetInfoBarResponse(const GURL& requesting_url, | 373 void GeolocationBrowserTest::SetInfoBarResponse(const GURL& requesting_url, |
| 374 bool allowed) { | 374 bool allowed) { |
| 375 WebContents* web_contents = | 375 WebContents* web_contents = |
| 376 current_browser_->tab_strip_model()->GetActiveWebContents(); | 376 current_browser_->tab_strip_model()->GetActiveWebContents(); |
| 377 TabSpecificContentSettings* content_settings = | 377 TabSpecificContentSettings* content_settings = |
| 378 TabSpecificContentSettings::FromWebContents(web_contents); | 378 TabSpecificContentSettings::FromWebContents(web_contents); |
| 379 const GeolocationSettingsState& settings_state = | 379 const ContentSettingsUsagesState& usages_state = |
| 380 content_settings->geolocation_settings_state(); | 380 content_settings->geolocation_usages_state(); |
| 381 size_t state_map_size = settings_state.state_map().size(); | 381 size_t state_map_size = usages_state.state_map().size(); |
| 382 ASSERT_TRUE(infobar_); | 382 ASSERT_TRUE(infobar_); |
| 383 LOG(WARNING) << "will set infobar response"; | 383 LOG(WARNING) << "will set infobar response"; |
| 384 { | 384 { |
| 385 content::WindowedNotificationObserver observer( | 385 content::WindowedNotificationObserver observer( |
| 386 content::NOTIFICATION_LOAD_STOP, | 386 content::NOTIFICATION_LOAD_STOP, |
| 387 content::Source<NavigationController>(&web_contents->GetController())); | 387 content::Source<NavigationController>(&web_contents->GetController())); |
| 388 if (allowed) | 388 if (allowed) |
| 389 infobar_->AsConfirmInfoBarDelegate()->Accept(); | 389 infobar_->AsConfirmInfoBarDelegate()->Accept(); |
| 390 else | 390 else |
| 391 infobar_->AsConfirmInfoBarDelegate()->Cancel(); | 391 infobar_->AsConfirmInfoBarDelegate()->Cancel(); |
| 392 observer.Wait(); | 392 observer.Wait(); |
| 393 } | 393 } |
| 394 | 394 |
| 395 InfoBarService::FromWebContents(web_contents)->RemoveInfoBar(infobar_); | 395 InfoBarService::FromWebContents(web_contents)->RemoveInfoBar(infobar_); |
| 396 LOG(WARNING) << "infobar response set"; | 396 LOG(WARNING) << "infobar response set"; |
| 397 infobar_ = NULL; | 397 infobar_ = NULL; |
| 398 EXPECT_GT(settings_state.state_map().size(), state_map_size); | 398 EXPECT_GT(usages_state.state_map().size(), state_map_size); |
| 399 GURL requesting_origin(requesting_url.GetOrigin()); | 399 GURL requesting_origin(requesting_url.GetOrigin()); |
| 400 EXPECT_EQ(1U, settings_state.state_map().count(requesting_origin)); | 400 EXPECT_EQ(1U, usages_state.state_map().count(requesting_origin)); |
| 401 ContentSetting expected_setting = | 401 ContentSetting expected_setting = |
| 402 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | 402 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
| 403 EXPECT_EQ(expected_setting, | 403 EXPECT_EQ(expected_setting, |
| 404 settings_state.state_map().find(requesting_origin)->second); | 404 usages_state.state_map().find(requesting_origin)->second); |
| 405 } | 405 } |
| 406 | 406 |
| 407 void GeolocationBrowserTest::CheckStringValueFromJavascriptForTab( | 407 void GeolocationBrowserTest::CheckStringValueFromJavascriptForTab( |
| 408 const std::string& expected, | 408 const std::string& expected, |
| 409 const std::string& function, | 409 const std::string& function, |
| 410 WebContents* web_contents) { | 410 WebContents* web_contents) { |
| 411 std::string script(base::StringPrintf( | 411 std::string script(base::StringPrintf( |
| 412 "window.domAutomationController.send(%s)", function.c_str())); | 412 "window.domAutomationController.send(%s)", function.c_str())); |
| 413 std::string result; | 413 std::string result; |
| 414 ASSERT_TRUE(content::ExecuteScriptInFrameAndExtractString( | 414 ASSERT_TRUE(content::ExecuteScriptInFrameAndExtractString( |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 | 732 |
| 733 set_iframe_xpath("//iframe[@id='iframe_2']"); | 733 set_iframe_xpath("//iframe[@id='iframe_2']"); |
| 734 AddGeolocationWatch(false); | 734 AddGeolocationWatch(false); |
| 735 | 735 |
| 736 std::string script = | 736 std::string script = |
| 737 "window.domAutomationController.send(window.close());"; | 737 "window.domAutomationController.send(window.close());"; |
| 738 bool result = content::ExecuteScript( | 738 bool result = content::ExecuteScript( |
| 739 current_browser()->tab_strip_model()->GetActiveWebContents(), script); | 739 current_browser()->tab_strip_model()->GetActiveWebContents(), script); |
| 740 EXPECT_EQ(result, true); | 740 EXPECT_EQ(result, true); |
| 741 } | 741 } |
| OLD | NEW |