diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-24 17:10:26 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-24 17:10:26 +0000 |
commit | f7f9819d66ea030ff43ca813ee87828cfce1fa29 (patch) | |
tree | 1b5c0d080c2b6066a1dff0f367d6efc02f7635bf | |
parent | b081d6c2216f187cd27b96f24489f8fbb038c8f1 (diff) | |
download | chromium_src-f7f9819d66ea030ff43ca813ee87828cfce1fa29.zip chromium_src-f7f9819d66ea030ff43ca813ee87828cfce1fa29.tar.gz chromium_src-f7f9819d66ea030ff43ca813ee87828cfce1fa29.tar.bz2 |
Get rid of a bunch of geolocation includes in chrome tests. I've created a simple mock class that tests which use geolocation can use to wrap this complexity.
BUG=98716
Review URL: https://chromiumcodereview.appspot.com/9285011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118850 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/DEPS | 5 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_geolocation_apitest.cc | 16 | ||||
-rw-r--r-- | chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc | 17 | ||||
-rw-r--r-- | chrome/browser/geolocation/geolocation_browsertest.cc | 54 | ||||
-rw-r--r-- | content/content_browser.gypi | 1 | ||||
-rw-r--r-- | content/content_tests.gypi | 2 | ||||
-rw-r--r-- | content/public/browser/access_token_store.cc | 15 | ||||
-rw-r--r-- | content/public/browser/access_token_store.h | 9 | ||||
-rw-r--r-- | content/test/mock_geolocation.cc | 39 | ||||
-rw-r--r-- | content/test/mock_geolocation.h | 40 |
10 files changed, 117 insertions, 81 deletions
diff --git a/chrome/browser/DEPS b/chrome/browser/DEPS index 06e065a..fae60ab 100644 --- a/chrome/browser/DEPS +++ b/chrome/browser/DEPS @@ -62,10 +62,6 @@ include_rules = [ "+content/browser/file_system/browser_file_system_helper.h", "+content/browser/find_pasteboard.h", "+content/browser/font_list_async.h", - "+content/browser/geolocation/arbitrator_dependency_factories_for_test.h", - "+content/browser/geolocation/location_arbitrator.h", - "+content/browser/geolocation/location_provider.h", - "+content/browser/geolocation/mock_location_provider.h", "+content/browser/geolocation/wifi_data_provider_common.h", "+content/browser/gpu/gpu_blacklist.h", "+content/browser/gpu/gpu_data_manager.h", @@ -147,6 +143,7 @@ include_rules = [ "+content/browser/zygote_host_linux.h", "-content/common", + "+content/common/geoposition.h", # TODO(jam): move to public # Other libraries. "+chrome/third_party/hunspell", diff --git a/chrome/browser/extensions/extension_geolocation_apitest.cc b/chrome/browser/extensions/extension_geolocation_apitest.cc index e24d783..3602b0c 100644 --- a/chrome/browser/extensions/extension_geolocation_apitest.cc +++ b/chrome/browser/extensions/extension_geolocation_apitest.cc @@ -3,32 +3,26 @@ // found in the LICENSE file. #include "chrome/browser/extensions/extension_apitest.h" -#include "content/browser/geolocation/location_arbitrator.h" -#include "content/browser/geolocation/mock_location_provider.h" -#include "content/browser/geolocation/arbitrator_dependency_factories_for_test.h" +#include "content/test/mock_geolocation.h" class GeolocationApiTest : public ExtensionApiTest { public: - GeolocationApiTest() - : dependency_factory_( - new GeolocationArbitratorDependencyFactoryWithLocationProvider( - &NewAutoSuccessMockLocationProvider)) { + GeolocationApiTest() { } // InProcessBrowserTest virtual void SetUpInProcessBrowserTestFixture() { ExtensionApiTest::SetUpInProcessBrowserTestFixture(); - GeolocationArbitrator::SetDependencyFactoryForTest( - dependency_factory_.get()); + mock_geolocation_.Setup(); } // InProcessBrowserTest virtual void TearDownInProcessBrowserTestFixture() { - GeolocationArbitrator::SetDependencyFactoryForTest(NULL); + mock_geolocation_.TearDown(); } private: - scoped_refptr<GeolocationArbitratorDependencyFactory> dependency_factory_; + content::MockGeolocation mock_geolocation_; }; IN_PROC_BROWSER_TEST_F(GeolocationApiTest, diff --git a/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc b/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc index 7380d46..26bd7e3 100644 --- a/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc +++ b/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc @@ -19,15 +19,12 @@ #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/test/base/testing_profile.h" -#include "content/browser/geolocation/arbitrator_dependency_factories_for_test.h" -#include "content/browser/geolocation/location_arbitrator.h" -#include "content/browser/geolocation/location_provider.h" -#include "content/browser/geolocation/mock_location_provider.h" #include "content/browser/renderer_host/mock_render_process_host.h" #include "content/browser/tab_contents/test_tab_contents.h" #include "content/public/browser/navigation_details.h" #include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_service.h" +#include "content/test/mock_geolocation.h" #include "content/test/test_browser_thread.h" #include "testing/gtest/include/gtest/gtest.h" @@ -142,7 +139,7 @@ class GeolocationPermissionContextTests : public TabContentsWrapperTestHarness { virtual void TearDown(); content::TestBrowserThread ui_thread_; - scoped_refptr<GeolocationArbitratorDependencyFactory> dependency_factory_; + content::MockGeolocation mock_geolocation_; // A map between renderer child id and a pair represending the bridge id and // whether the requested permission was allowed. @@ -151,10 +148,7 @@ class GeolocationPermissionContextTests : public TabContentsWrapperTestHarness { GeolocationPermissionContextTests::GeolocationPermissionContextTests() : TabContentsWrapperTestHarness(), - ui_thread_(BrowserThread::UI, MessageLoop::current()), - dependency_factory_( - new GeolocationArbitratorDependencyFactoryWithLocationProvider( - &NewAutoSuccessMockNetworkLocationProvider)) { + ui_thread_(BrowserThread::UI, MessageLoop::current()) { } GeolocationPermissionContextTests::~GeolocationPermissionContextTests() { @@ -235,14 +229,13 @@ void GeolocationPermissionContextTests::CheckTabContentsState( void GeolocationPermissionContextTests::SetUp() { TabContentsWrapperTestHarness::SetUp(); - GeolocationArbitrator::SetDependencyFactoryForTest( - dependency_factory_.get()); + mock_geolocation_.Setup(); geolocation_permission_context_ = new ChromeGeolocationPermissionContext(profile()); } void GeolocationPermissionContextTests::TearDown() { - GeolocationArbitrator::SetDependencyFactoryForTest(NULL); + mock_geolocation_.TearDown(); TabContentsWrapperTestHarness::TearDown(); } diff --git a/chrome/browser/geolocation/geolocation_browsertest.cc b/chrome/browser/geolocation/geolocation_browsertest.cc index 7d5cd85..6acaa53 100644 --- a/chrome/browser/geolocation/geolocation_browsertest.cc +++ b/chrome/browser/geolocation/geolocation_browsertest.cc @@ -24,14 +24,13 @@ #include "chrome/common/content_settings_pattern.h" #include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/ui_test_utils.h" -#include "content/browser/geolocation/arbitrator_dependency_factories_for_test.h" -#include "content/browser/geolocation/location_arbitrator.h" -#include "content/browser/geolocation/mock_location_provider.h" #include "content/browser/renderer_host/render_view_host.h" +#include "content/common/geoposition.h" #include "content/public/browser/navigation_controller.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/notification_details.h" #include "content/public/browser/web_contents.h" +#include "content/test/mock_geolocation.h" #include "net/base/net_util.h" #include "net/test/test_server.h" @@ -191,12 +190,6 @@ class GeolocationNotificationObserver : public content::NotificationObserver { std::string javascript_response_; }; -void NotifyGeoposition(const Geoposition& geoposition) { - DCHECK(MockLocationProvider::instance_); - MockLocationProvider::instance_->HandlePositionChanged(geoposition); - LOG(WARNING) << "MockLocationProvider listeners updated"; -} - // This is a browser test for Geolocation. // It exercises various integration points from javascript <-> browser: // 1. Infobar is displayed when a geolocation is requested from an unauthorized @@ -212,23 +205,19 @@ class GeolocationBrowserTest : public InProcessBrowserTest { : infobar_(NULL), current_browser_(NULL), html_for_tests_("files/geolocation/simple.html"), - started_test_server_(false), - dependency_factory_( - new GeolocationArbitratorDependencyFactoryWithLocationProvider( - &NewAutoSuccessMockNetworkLocationProvider)) { + started_test_server_(false) { EnableDOMAutomation(); } // InProcessBrowserTest virtual void SetUpInProcessBrowserTestFixture() { - GeolocationArbitrator::SetDependencyFactoryForTest( - dependency_factory_.get()); + mock_geolocation_.Setup(); } // InProcessBrowserTest virtual void TearDownInProcessBrowserTestFixture() { LOG(WARNING) << "TearDownInProcessBrowserTestFixture. Test Finished."; - GeolocationArbitrator::SetDependencyFactoryForTest(NULL); + mock_geolocation_.TearDown(); } enum InitializationOptions { @@ -366,6 +355,11 @@ class GeolocationBrowserTest : public InProcessBrowserTest { expected, function, current_browser_->GetSelectedWebContents()); } + void NotifyGeoposition(const Geoposition& geoposition) { + mock_geolocation_.SetCurrentPosition(geoposition); + LOG(WARNING) << "MockLocationProvider listeners updated"; + } + InfoBarDelegate* infobar_; Browser* current_browser_; // path element of a URL referencing the html content for this test. @@ -381,7 +375,7 @@ class GeolocationBrowserTest : public InProcessBrowserTest { // TODO(phajdan.jr): Remove after we can ask TestServer whether it is started. bool started_test_server_; - scoped_refptr<GeolocationArbitratorDependencyFactory> dependency_factory_; + content::MockGeolocation mock_geolocation_; }; IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, DisplaysPermissionBar) { @@ -393,7 +387,7 @@ IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, Geoposition) { ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); AddGeolocationWatch(true); SetInfobarResponse(current_url_, true); - CheckGeoposition(MockLocationProvider::instance_->position_); + CheckGeoposition(mock_geolocation_.GetCurrentPosition()); } // Crashy, http://crbug.com/70585. @@ -422,7 +416,7 @@ IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_NoInfobarForSecondTab) { // Checks infobar will not be created a second tab. ASSERT_TRUE(Initialize(INITIALIZATION_NEWTAB)); AddGeolocationWatch(false); - CheckGeoposition(MockLocationProvider::instance_->position_); + CheckGeoposition(mock_geolocation_.GetCurrentPosition()); } // http://crbug.com/44589. Hangs on Mac, crashes on Windows @@ -464,7 +458,7 @@ IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_NoInfobarForAllowedOrigin) CONTENT_SETTING_ALLOW); // Checks no infobar will be created and there's no error callback. AddGeolocationWatch(false); - CheckGeoposition(MockLocationProvider::instance_->position_); + CheckGeoposition(mock_geolocation_.GetCurrentPosition()); } IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoInfobarForOffTheRecord) { @@ -473,13 +467,13 @@ IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoInfobarForOffTheRecord) { AddGeolocationWatch(true); // Response will be persisted SetInfobarResponse(current_url_, true); - CheckGeoposition(MockLocationProvider::instance_->position_); + CheckGeoposition(mock_geolocation_.GetCurrentPosition()); // Disables further prompts from this tab. CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); // Go incognito, and checks no infobar will be created. ASSERT_TRUE(Initialize(INITIALIZATION_OFFTHERECORD)); AddGeolocationWatch(false); - CheckGeoposition(MockLocationProvider::instance_->position_); + CheckGeoposition(mock_geolocation_.GetCurrentPosition()); } // Test fails: http://crbug.com/90927 @@ -493,7 +487,7 @@ IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, iframe_xpath_ = L"//iframe[@id='iframe_0']"; AddGeolocationWatch(true); SetInfobarResponse(iframe_urls_[0], true); - CheckGeoposition(MockLocationProvider::instance_->position_); + CheckGeoposition(mock_geolocation_.GetCurrentPosition()); // Disables further prompts from this iframe. CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); @@ -505,8 +499,6 @@ IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, // Back to the first frame, enable navigation and refresh geoposition. iframe_xpath_ = L"//iframe[@id='iframe_0']"; CheckStringValueFromJavascript("1", "geoSetMaxNavigateCount(1)"); - // MockLocationProvider must have been created. - ASSERT_TRUE(MockLocationProvider::instance_); Geoposition fresh_position = GeopositionFromLatLong(3.17, 4.23); ui_test_utils::WindowedNotificationObserver observer( content::NOTIFICATION_LOAD_STOP, @@ -538,12 +530,10 @@ IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, iframe_xpath_ = L"//iframe[@id='iframe_0']"; AddGeolocationWatch(true); SetInfobarResponse(iframe_urls_[0], true); - CheckGeoposition(MockLocationProvider::instance_->position_); + CheckGeoposition(mock_geolocation_.GetCurrentPosition()); // Refresh geoposition, but let's not yet create the watch on the second frame // so that it'll fetch from cache. - // MockLocationProvider must have been created. - ASSERT_TRUE(MockLocationProvider::instance_); Geoposition cached_position = GeopositionFromLatLong(5.67, 8.09); ui_test_utils::WindowedNotificationObserver observer( content::NOTIFICATION_LOAD_STOP, @@ -578,7 +568,7 @@ IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, iframe_xpath_ = L"//iframe[@id='iframe_0']"; AddGeolocationWatch(true); SetInfobarResponse(iframe_urls_[0], true); - CheckGeoposition(MockLocationProvider::instance_->position_); + CheckGeoposition(mock_geolocation_.GetCurrentPosition()); // Disables further prompts from this iframe. CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); @@ -622,14 +612,14 @@ IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, DISABLED_NoInfoBarBeforeStart) { iframe_xpath_ = L"//iframe[@id='iframe_0']"; AddGeolocationWatch(true); SetInfobarResponse(iframe_urls_[0], true); - CheckGeoposition(MockLocationProvider::instance_->position_); + CheckGeoposition(mock_geolocation_.GetCurrentPosition()); CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); // Permission should be requested after adding a watch. iframe_xpath_ = L"//iframe[@id='iframe_1']"; AddGeolocationWatch(true); SetInfobarResponse(iframe_urls_[1], true); - CheckGeoposition(MockLocationProvider::instance_->position_); + CheckGeoposition(mock_geolocation_.GetCurrentPosition()); } IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, TwoWatchesInOneFrame) { @@ -649,7 +639,7 @@ IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, TwoWatchesInOneFrame) { // Send a position which both geolocation watches will receive. AddGeolocationWatch(true); SetInfobarResponse(current_url_, true); - CheckGeoposition(MockLocationProvider::instance_->position_); + CheckGeoposition(mock_geolocation_.GetCurrentPosition()); // The second watch will now have cancelled. Ensure an update still makes // its way through to the first watcher. diff --git a/content/content_browser.gypi b/content/content_browser.gypi index ce38ebc..e4d73c3 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -25,7 +25,6 @@ '<(INTERMEDIATE_DIR)', ], 'sources': [ - 'public/browser/access_token_store.cc', 'public/browser/access_token_store.h', 'public/browser/browser_child_process_host.h', 'public/browser/browser_child_process_host_delegate.cc', diff --git a/content/content_tests.gypi b/content/content_tests.gypi index 2e3e4b5..8208507 100644 --- a/content/content_tests.gypi +++ b/content/content_tests.gypi @@ -86,6 +86,8 @@ 'test/content_test_suite.cc', 'test/content_test_suite.h', 'test/js_injection_ready_observer.h', + 'test/mock_geolocation.cc', + 'test/mock_geolocation.h', 'test/mock_keyboard.cc', 'test/mock_keyboard.h', 'test/mock_keyboard_driver_win.cc', diff --git a/content/public/browser/access_token_store.cc b/content/public/browser/access_token_store.cc deleted file mode 100644 index ba563f4..0000000 --- a/content/public/browser/access_token_store.cc +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/public/browser/access_token_store.h" - -namespace content { - -AccessTokenStore::AccessTokenStore() { -} - -AccessTokenStore::~AccessTokenStore() { -} - -} // namespace content diff --git a/content/public/browser/access_token_store.h b/content/public/browser/access_token_store.h index 1dfaabf..dbfd6e0 100644 --- a/content/public/browser/access_token_store.h +++ b/content/public/browser/access_token_store.h @@ -44,7 +44,7 @@ class AccessTokenStore : public base::RefCountedThreadSafe<AccessTokenStore> { // in Chrome the call to obtain this must also be performed on the UI thread // so it is efficient to piggyback it onto this request. // Takes ownership of |callback|. - CONTENT_EXPORT virtual void LoadAccessTokens( + virtual void LoadAccessTokens( const LoadAccessTokensCallbackType& callback) = 0; virtual void SaveAccessToken( @@ -52,11 +52,8 @@ class AccessTokenStore : public base::RefCountedThreadSafe<AccessTokenStore> { protected: friend class base::RefCountedThreadSafe<AccessTokenStore>; - CONTENT_EXPORT AccessTokenStore(); - CONTENT_EXPORT virtual ~AccessTokenStore(); - - private: - DISALLOW_COPY_AND_ASSIGN(AccessTokenStore); + CONTENT_EXPORT AccessTokenStore() {} + CONTENT_EXPORT virtual ~AccessTokenStore() {} }; } // namespace content diff --git a/content/test/mock_geolocation.cc b/content/test/mock_geolocation.cc new file mode 100644 index 0000000..54085b1 --- /dev/null +++ b/content/test/mock_geolocation.cc @@ -0,0 +1,39 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/test/mock_geolocation.h" + +#include "content/browser/geolocation/arbitrator_dependency_factories_for_test.h" +#include "content/browser/geolocation/location_arbitrator.h" +#include "content/browser/geolocation/mock_location_provider.h" + +namespace content { + +MockGeolocation::MockGeolocation() { + dependency_factory_ = + new GeolocationArbitratorDependencyFactoryWithLocationProvider( + &NewAutoSuccessMockLocationProvider); +} + +MockGeolocation::~MockGeolocation() { +} + +void MockGeolocation::Setup() { + GeolocationArbitrator::SetDependencyFactoryForTest( + dependency_factory_.get()); +} + +void MockGeolocation::TearDown() { + GeolocationArbitrator::SetDependencyFactoryForTest(NULL); +} + +Geoposition MockGeolocation::GetCurrentPosition() const { + return MockLocationProvider::instance_->position_; +} + +void MockGeolocation::SetCurrentPosition(const Geoposition& position) { + MockLocationProvider::instance_->HandlePositionChanged(position); +} + +} // namespace content diff --git a/content/test/mock_geolocation.h b/content/test/mock_geolocation.h new file mode 100644 index 0000000..309e890 --- /dev/null +++ b/content/test/mock_geolocation.h @@ -0,0 +1,40 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_TEST_MOCK_GEOLOCATION_H_ +#define CONTENT_TEST_MOCK_GEOLOCATION_H_ +#pragma once + +#include "base/basictypes.h" +#include "base/memory/ref_counted.h" + +class GeolocationArbitratorDependencyFactory; +struct Geoposition; + +namespace content { + +// Creates a mock location provider that gives a valid location. +class MockGeolocation { + public: + MockGeolocation(); + ~MockGeolocation(); + + // Call this in the test's Setup function. + void Setup(); + + // Call this in the test's TearDown function. + void TearDown(); + + Geoposition GetCurrentPosition() const; + void SetCurrentPosition(const Geoposition& position); + + private: + scoped_refptr<GeolocationArbitratorDependencyFactory> dependency_factory_; + + DISALLOW_COPY_AND_ASSIGN(MockGeolocation); +}; + +} // namespace content + +#endif // CONTENT_TEST_MOCK_GEOLOCATION_H_ |