| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/string_util.h" | 5 #include "base/string_util.h" |
| 6 #include "chrome/browser/app_modal_dialog.h" | 6 #include "chrome/browser/app_modal_dialog.h" |
| 7 #include "chrome/browser/browser.h" | 7 #include "chrome/browser/browser.h" |
| 8 #include "chrome/browser/browser_list.h" | 8 #include "chrome/browser/browser_list.h" |
| 9 #include "chrome/browser/geolocation/location_arbitrator.h" | 9 #include "chrome/browser/geolocation/location_arbitrator.h" |
| 10 #include "chrome/browser/geolocation/mock_location_provider.h" | 10 #include "chrome/browser/geolocation/mock_location_provider.h" |
| 11 #include "chrome/browser/host_content_settings_map.h" |
| 11 #include "chrome/browser/profile.h" | 12 #include "chrome/browser/profile.h" |
| 12 #include "chrome/browser/renderer_host/render_view_host.h" | 13 #include "chrome/browser/renderer_host/render_view_host.h" |
| 13 #include "chrome/browser/tab_contents/tab_contents.h" | 14 #include "chrome/browser/tab_contents/tab_contents.h" |
| 14 #include "chrome/common/chrome_paths.h" | 15 #include "chrome/common/chrome_paths.h" |
| 15 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 17 #include "chrome/common/content_settings.h" |
| 18 #include "chrome/common/content_settings_types.h" |
| 16 #include "chrome/common/geoposition.h" | 19 #include "chrome/common/geoposition.h" |
| 17 #include "chrome/common/notification_details.h" | 20 #include "chrome/common/notification_details.h" |
| 18 #include "chrome/common/notification_service.h" | 21 #include "chrome/common/notification_service.h" |
| 19 #include "chrome/common/notification_type.h" | 22 #include "chrome/common/notification_type.h" |
| 20 #include "chrome/common/render_messages.h" | 23 #include "chrome/common/render_messages.h" |
| 21 #include "chrome/test/in_process_browser_test.h" | 24 #include "chrome/test/in_process_browser_test.h" |
| 22 #include "chrome/test/ui_test_utils.h" | 25 #include "chrome/test/ui_test_utils.h" |
| 23 #include "net/base/net_util.h" | 26 #include "net/base/net_util.h" |
| 24 | 27 |
| 25 class InfobarNotificationObserver : public NotificationObserver { | 28 class InfobarNotificationObserver : public NotificationObserver { |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 | 218 |
| 216 #if defined(OS_MACOSX) | 219 #if defined(OS_MACOSX) |
| 217 // TODO(bulach): investigate why this fails on mac. It may be related to: | 220 // TODO(bulach): investigate why this fails on mac. It may be related to: |
| 218 // http://crbug.com//29424 | 221 // http://crbug.com//29424 |
| 219 #define MAYBE_NoInfobarForSecondTab DISABLED_NoInfobarForSecondTab | 222 #define MAYBE_NoInfobarForSecondTab DISABLED_NoInfobarForSecondTab |
| 220 #else | 223 #else |
| 221 #define MAYBE_NoInfobarForSecondTab NoInfobarForSecondTab | 224 #define MAYBE_NoInfobarForSecondTab NoInfobarForSecondTab |
| 222 #endif | 225 #endif |
| 223 | 226 |
| 224 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_NoInfobarForSecondTab) { | 227 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_NoInfobarForSecondTab) { |
| 225 #if 0 | |
| 226 // TODO(bulach): enable this test once we use HostContentSettingsMap instead | 228 // TODO(bulach): enable this test once we use HostContentSettingsMap instead |
| 227 // of files. | 229 // of files. |
| 228 Initialize(INITIALIZATION_NONE); | 230 Initialize(INITIALIZATION_NONE); |
| 229 SendGeoposition(true, Geoposition()); | 231 SendGeoposition(true, Geoposition()); |
| 230 SetInfobarResponse(true); | 232 SetInfobarResponse(true); |
| 231 // Checks infobar will not be created a second tab. | 233 // Checks infobar will not be created a second tab. |
| 232 Initialize(INITIALIZATION_NEWTAB); | 234 Initialize(INITIALIZATION_NEWTAB); |
| 233 SendGeoposition(false, Geoposition()); | 235 SendGeoposition(false, Geoposition()); |
| 234 CheckValueFromJavascript("0", "geoGetLastError()"); | 236 CheckValueFromJavascript("0", "geoGetLastError()"); |
| 235 #endif | |
| 236 } | 237 } |
| 237 | 238 |
| 238 #if defined(OS_MACOSX) | 239 #if defined(OS_MACOSX) |
| 239 // TODO(bulach): investigate why this fails on mac. It may be related to: | 240 // TODO(bulach): investigate why this fails on mac. It may be related to: |
| 240 // http://crbug.com//29424 | 241 // http://crbug.com//29424 |
| 241 #define MAYBE_NoInfobarForDeniedOrigin DISABLED_NoInfobarForDeniedOrigin | 242 #define MAYBE_NoInfobarForDeniedOrigin DISABLED_NoInfobarForDeniedOrigin |
| 242 #else | 243 #else |
| 243 #define MAYBE_NoInfobarForDeniedOrigin NoInfobarForDeniedOrigin | 244 #define MAYBE_NoInfobarForDeniedOrigin NoInfobarForDeniedOrigin |
| 244 #endif | 245 #endif |
| 245 | 246 |
| 246 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_NoInfobarForDeniedOrigin) { | 247 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_NoInfobarForDeniedOrigin) { |
| 247 #if 0 | |
| 248 // TODO(bulach): enable this test once we use HostContentSettingsMap instead | |
| 249 // of files. | |
| 250 WritePermissionFile("{\"allowed\":false}"); | |
| 251 // Checks no infobar will be created. | 248 // Checks no infobar will be created. |
| 252 Initialize(INITIALIZATION_NONE); | 249 Initialize(INITIALIZATION_NONE); |
| 250 current_browser_->profile()->GetHostContentSettingsMap()->SetContentSetting( |
| 251 "localhost", CONTENT_SETTINGS_TYPE_GEOLOCATION, CONTENT_SETTING_BLOCK); |
| 253 SendGeoposition(false, Geoposition()); | 252 SendGeoposition(false, Geoposition()); |
| 254 CheckValueFromJavascript("1", "geoGetLastError()"); | 253 CheckValueFromJavascript("1", "geoGetLastError()"); |
| 255 // Checks infobar will not be created a second tab. | 254 // Checks infobar will not be created a second tab. |
| 256 Initialize(INITIALIZATION_NEWTAB); | 255 Initialize(INITIALIZATION_NEWTAB); |
| 257 SendGeoposition(false, Geoposition()); | 256 SendGeoposition(false, Geoposition()); |
| 258 CheckValueFromJavascript("1", "geoGetLastError()"); | 257 CheckValueFromJavascript("1", "geoGetLastError()"); |
| 259 #endif | |
| 260 } | 258 } |
| 261 | 259 |
| 262 #if defined(OS_MACOSX) | 260 #if defined(OS_MACOSX) |
| 263 // TODO(bulach): investigate why this fails on mac. It may be related to: | 261 // TODO(bulach): investigate why this fails on mac. It may be related to: |
| 264 // http://crbug.com//29424 | 262 // http://crbug.com//29424 |
| 265 #define MAYBE_NoInfobarForAllowedOrigin DISABLED_NoInfobarForAllowedOrigin | 263 #define MAYBE_NoInfobarForAllowedOrigin DISABLED_NoInfobarForAllowedOrigin |
| 266 #else | 264 #else |
| 267 #define MAYBE_NoInfobarForAllowedOrigin NoInfobarForAllowedOrigin | 265 #define MAYBE_NoInfobarForAllowedOrigin NoInfobarForAllowedOrigin |
| 268 #endif | 266 #endif |
| 269 | 267 |
| 270 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, | 268 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, |
| 271 MAYBE_NoInfobarForAllowedOrigin) { | 269 MAYBE_NoInfobarForAllowedOrigin) { |
| 272 #if 0 | |
| 273 // TODO(bulach): enable this test once we use HostContentSettingsMap instead | |
| 274 // of files. | |
| 275 WritePermissionFile("{\"allowed\":true}"); | |
| 276 // Checks no infobar will be created and there's no error callback. | 270 // Checks no infobar will be created and there's no error callback. |
| 277 Initialize(INITIALIZATION_NONE); | 271 Initialize(INITIALIZATION_NONE); |
| 272 current_browser_->profile()->GetHostContentSettingsMap()->SetContentSetting( |
| 273 "localhost", CONTENT_SETTINGS_TYPE_GEOLOCATION, CONTENT_SETTING_ALLOW); |
| 278 SendGeoposition(false, Geoposition()); | 274 SendGeoposition(false, Geoposition()); |
| 279 CheckValueFromJavascript("0", "geoGetLastError()"); | 275 CheckValueFromJavascript("0", "geoGetLastError()"); |
| 280 #endif | |
| 281 } | 276 } |
| 282 | 277 |
| 283 #if defined(OS_MACOSX) | 278 #if defined(OS_MACOSX) |
| 284 // TODO(bulach): investigate why this fails on mac. It may be related to: | 279 // TODO(bulach): investigate why this fails on mac. It may be related to: |
| 285 // http://crbug.com//29424 | 280 // http://crbug.com//29424 |
| 286 #define MAYBE_InfobarForOffTheRecord DISABLED_InfobarForOffTheRecord | 281 #define MAYBE_InfobarForOffTheRecord DISABLED_InfobarForOffTheRecord |
| 287 #else | 282 #else |
| 288 #define MAYBE_InfobarForOffTheRecord InfobarForOffTheRecord | 283 #define MAYBE_InfobarForOffTheRecord InfobarForOffTheRecord |
| 289 #endif | 284 #endif |
| 290 | 285 |
| 291 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_InfobarForOffTheRecord) { | 286 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_NoInfobarForOffTheRecord) { |
| 292 // Checks infobar will be created for regular profile. | 287 // Checks infobar will be created for regular profile. |
| 293 Initialize(INITIALIZATION_NONE); | 288 Initialize(INITIALIZATION_NONE); |
| 294 SendGeoposition(true, Geoposition()); | 289 SendGeoposition(true, Geoposition()); |
| 295 SetInfobarResponse(true); | 290 SetInfobarResponse(true); |
| 296 CheckValueFromJavascript("0", "geoGetLastError()"); | 291 CheckValueFromJavascript("0", "geoGetLastError()"); |
| 297 // Go off the record, and checks infobar will be created and an error callback | 292 // Go off the record, and checks no infobar will be created and no error |
| 298 // is triggered. | 293 // callback is triggered. |
| 299 Initialize(INITIALIZATION_OFFTHERECORD); | 294 Initialize(INITIALIZATION_OFFTHERECORD); |
| 300 SendGeoposition(true, Geoposition()); | 295 SendGeoposition(false, Geoposition()); |
| 301 SetInfobarResponse(false); | 296 CheckValueFromJavascript("0", "geoGetLastError()"); |
| 302 CheckValueFromJavascript("1", "geoGetLastError()"); | |
| 303 } | 297 } |
| 304 | 298 |
| 305 #if defined(OS_MACOSX) | 299 #if defined(OS_MACOSX) |
| 306 // TODO(bulach): investigate why this fails on mac. It may be related to: | 300 // TODO(bulach): investigate why this fails on mac. It may be related to: |
| 307 // http://crbug.com//29424 | 301 // http://crbug.com//29424 |
| 308 #define MAYBE_Geoposition DISABLED_Geoposition | 302 #define MAYBE_Geoposition DISABLED_Geoposition |
| 309 #else | 303 #else |
| 310 #define MAYBE_Geoposition Geoposition | 304 #define MAYBE_Geoposition Geoposition |
| 311 #endif | 305 #endif |
| 312 | 306 |
| 313 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_Geoposition) { | 307 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_Geoposition) { |
| 314 // Checks infobar will be created. | 308 // Checks infobar will be created. |
| 315 Initialize(INITIALIZATION_NONE); | 309 Initialize(INITIALIZATION_NONE); |
| 316 SendGeoposition(true, Geoposition()); | 310 SendGeoposition(true, Geoposition()); |
| 317 // Infobar was displayed, allow access and check there's no error code. | 311 // Infobar was displayed, allow access and check there's no error code. |
| 318 SetInfobarResponse(true); | 312 SetInfobarResponse(true); |
| 319 CheckValueFromJavascript("0", "geoGetLastError()"); | 313 CheckValueFromJavascript("0", "geoGetLastError()"); |
| 320 // Sends a Geoposition over IPC, and check it arrives in the javascript side. | 314 // Sends a Geoposition over IPC, and check it arrives in the javascript side. |
| 321 Geoposition geoposition; | 315 Geoposition geoposition; |
| 322 geoposition.latitude = 3.17; | 316 geoposition.latitude = 3.17; |
| 323 geoposition.longitude = 4.23; | 317 geoposition.longitude = 4.23; |
| 324 SendGeoposition(false, geoposition); | 318 SendGeoposition(false, geoposition); |
| 325 // Checks we have no error. | 319 // Checks we have no error. |
| 326 CheckValueFromJavascript("0", "geoGetLastError()"); | 320 CheckValueFromJavascript("0", "geoGetLastError()"); |
| 327 CheckValueFromJavascript( | 321 CheckValueFromJavascript( |
| 328 DoubleToString(geoposition.latitude), "geoGetLastPositionLatitude()"); | 322 DoubleToString(geoposition.latitude), "geoGetLastPositionLatitude()"); |
| 329 CheckValueFromJavascript( | 323 CheckValueFromJavascript( |
| 330 DoubleToString(geoposition.longitude), "geoGetLastPositionLongitude()"); | 324 DoubleToString(geoposition.longitude), "geoGetLastPositionLongitude()"); |
| 331 } | 325 } |
| OLD | NEW |