Commit b9129716 authored by jamescook's avatar jamescook Committed by Commit bot

Move AppWindowGeometryCacheTest to extensions_unittests

It was running in Chrome's unit_tests for historical reasons.

* Remove usage of Chrome's TestExtensionPrefs by instantiating our own
  simplified ExtensionPrefs.
* Move ShellAppSorting to NullAppSorting so it can be used for the above
  as well as app_shell.

BUG=397164
TEST=extensions_unittests

Review URL: https://codereview.chromium.org/549663002

Cr-Commit-Position: refs/heads/master@{#293768}
parent 9cd9f5a5
......@@ -534,7 +534,6 @@
# extensions_unittests running in the bots yet. Until that happens,
# they should be kept here.
'../extensions/browser/api/power/power_api_unittest.cc',
'../extensions/browser/app_window/app_window_geometry_cache_unittest.cc',
'../extensions/common/extension_l10n_util_unittest.cc',
'../extensions/common/features/base_feature_provider_unittest.cc',
'../extensions/common/features/complex_feature_unittest.cc',
......
......@@ -2,15 +2,22 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "extensions/browser/app_window/app_window_geometry_cache.h"
#include "base/files/file_path.h"
#include "base/memory/scoped_ptr.h"
#include "base/prefs/mock_pref_change_callback.h"
#include "base/prefs/pref_service_factory.h"
#include "base/prefs/testing_pref_store.h"
#include "base/strings/string_number_conversions.h"
#include "chrome/browser/extensions/test_extension_prefs.h"
#include "chrome/test/base/testing_profile.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "content/public/test/test_browser_context.h"
#include "content/public/test/test_browser_thread.h"
#include "content/public/test/test_utils.h"
#include "extensions/browser/app_window/app_window_geometry_cache.h"
#include "extensions/browser/extension_pref_value_map.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extensions_test.h"
#include "extensions/browser/null_app_sorting.h"
#include "extensions/common/extension_builder.h"
#include "extensions/common/value_builder.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -35,16 +42,14 @@ scoped_refptr<Extension> CreateExtension(const std::string& id) {
} // namespace
// Base class for tests.
class AppWindowGeometryCacheTest : public testing::Test {
class AppWindowGeometryCacheTest : public ExtensionsTest {
public:
AppWindowGeometryCacheTest()
: profile_(new TestingProfile),
ui_thread_(BrowserThread::UI, &ui_message_loop_) {
prefs_.reset(new TestExtensionPrefs(
ui_message_loop_.message_loop_proxy().get()));
cache_.reset(new AppWindowGeometryCache(profile_.get(), prefs_->prefs()));
cache_->SetSyncDelayForTests(0);
}
: ui_thread_(BrowserThread::UI, &ui_message_loop_) {}
// testing::Test overrides:
virtual void SetUp() OVERRIDE;
virtual void TearDown() OVERRIDE;
void AddGeometryAndLoadExtension(const std::string& extension_id,
const std::string& window_id,
......@@ -59,14 +64,55 @@ class AppWindowGeometryCacheTest : public testing::Test {
void LoadExtension(const std::string& extension_id);
void UnloadExtension(const std::string& extension_id);
// Creates and adds an extension with associated prefs. Returns the extension
// ID.
std::string AddExtensionWithPrefs(const std::string& name);
protected:
scoped_ptr<TestingProfile> profile_;
base::MessageLoopForUI ui_message_loop_;
content::TestBrowserThread ui_thread_;
scoped_ptr<TestExtensionPrefs> prefs_;
scoped_ptr<ExtensionPrefValueMap> extension_pref_value_map_;
scoped_ptr<PrefService> pref_service_;
scoped_ptr<ExtensionPrefs> extension_prefs_;
scoped_ptr<AppWindowGeometryCache> cache_;
};
void AppWindowGeometryCacheTest::SetUp() {
ExtensionsTest::SetUp();
// Set up all the dependencies of ExtensionPrefs.
extension_pref_value_map_.reset(new ExtensionPrefValueMap);
base::PrefServiceFactory factory;
factory.set_user_prefs(new TestingPrefStore);
factory.set_extension_prefs(new TestingPrefStore);
user_prefs::PrefRegistrySyncable* pref_registry =
new user_prefs::PrefRegistrySyncable;
// Prefs should be registered before the PrefService is created.
ExtensionPrefs::RegisterProfilePrefs(pref_registry);
pref_service_ = factory.Create(pref_registry).Pass();
extension_prefs_.reset(ExtensionPrefs::Create(
pref_service_.get(),
browser_context()->GetPath().AppendASCII("Extensions"),
extension_pref_value_map_.get(),
scoped_ptr<AppSorting>(new NullAppSorting),
false /* extensions_disabled */,
std::vector<ExtensionPrefsObserver*>()));
cache_.reset(
new AppWindowGeometryCache(browser_context(), extension_prefs_.get()));
cache_->SetSyncDelayForTests(0);
}
void AppWindowGeometryCacheTest::TearDown() {
cache_.reset();
extension_prefs_.reset();
pref_service_.reset();
extension_pref_value_map_.reset();
ExtensionsTest::TearDown();
}
void AppWindowGeometryCacheTest::AddGeometryAndLoadExtension(
const std::string& extension_id,
const std::string& window_id,
......@@ -85,7 +131,7 @@ void AppWindowGeometryCacheTest::AddGeometryAndLoadExtension(
value->SetInteger("screen_bounds_h", screen_bounds.height());
value->SetInteger("state", state);
dict->SetWithoutPathExpansion(window_id, value);
prefs_->prefs()->SetGeometryCache(extension_id, dict.Pass());
extension_prefs_->SetGeometryCache(extension_id, dict.Pass());
LoadExtension(extension_id);
}
......@@ -102,23 +148,43 @@ void AppWindowGeometryCacheTest::LoadExtension(
void AppWindowGeometryCacheTest::UnloadExtension(
const std::string& extension_id) {
scoped_refptr<Extension> extension = CreateExtension(extension_id);
cache_->OnExtensionUnloaded(
profile_.get(),
extension.get(),
UnloadedExtensionInfo::REASON_DISABLE);
cache_->OnExtensionUnloaded(browser_context(),
extension.get(),
UnloadedExtensionInfo::REASON_DISABLE);
WaitForSync();
}
std::string AppWindowGeometryCacheTest::AddExtensionWithPrefs(
const std::string& name) {
// Generate the extension with a path based on the name so that extensions
// with different names will have different IDs.
base::FilePath path =
browser_context()->GetPath().AppendASCII("Extensions").AppendASCII(name);
scoped_refptr<Extension> extension =
ExtensionBuilder()
.SetManifest(
DictionaryBuilder().Set("name", "test").Set("version", "0.1"))
.SetPath(path)
.Build();
extension_prefs_->OnExtensionInstalled(
extension.get(),
Extension::ENABLED,
syncer::StringOrdinal::CreateInitialOrdinal(),
std::string());
return extension->id();
}
// Test getting geometry from an empty store.
TEST_F(AppWindowGeometryCacheTest, GetGeometryEmptyStore) {
const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1");
const std::string extension_id = AddExtensionWithPrefs("ext1");
ASSERT_FALSE(cache_->GetGeometry(extension_id, kWindowId, NULL, NULL, NULL));
}
// Test getting geometry for an unknown extension.
TEST_F(AppWindowGeometryCacheTest, GetGeometryUnkownExtension) {
const std::string extension_id1 = prefs_->AddExtensionAndReturnId("ext1");
const std::string extension_id2 = prefs_->AddExtensionAndReturnId("ext2");
const std::string extension_id1 = AddExtensionWithPrefs("ext1");
const std::string extension_id2 = AddExtensionWithPrefs("ext2");
AddGeometryAndLoadExtension(extension_id1,
kWindowId,
gfx::Rect(4, 5, 31, 43),
......@@ -129,7 +195,7 @@ TEST_F(AppWindowGeometryCacheTest, GetGeometryUnkownExtension) {
// Test getting geometry for an unknown window in a known extension.
TEST_F(AppWindowGeometryCacheTest, GetGeometryUnkownWindow) {
const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1");
const std::string extension_id = AddExtensionWithPrefs("ext1");
AddGeometryAndLoadExtension(extension_id,
kWindowId,
gfx::Rect(4, 5, 31, 43),
......@@ -141,7 +207,7 @@ TEST_F(AppWindowGeometryCacheTest, GetGeometryUnkownWindow) {
// Test that loading geometry, screen_bounds and state from the store works
// correctly.
TEST_F(AppWindowGeometryCacheTest, GetGeometryAndStateFromStore) {
const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1");
const std::string extension_id = AddExtensionWithPrefs("ext1");
gfx::Rect bounds(4, 5, 31, 43);
gfx::Rect screen_bounds(0, 0, 1600, 900);
ui::WindowShowState state = ui::SHOW_STATE_NORMAL;
......@@ -159,7 +225,7 @@ TEST_F(AppWindowGeometryCacheTest, GetGeometryAndStateFromStore) {
// Test corrupt bounds will not be loaded.
TEST_F(AppWindowGeometryCacheTest, CorruptBounds) {
const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1");
const std::string extension_id = AddExtensionWithPrefs("ext1");
gfx::Rect bounds;
gfx::Rect screen_bounds(0, 0, 1600, 900);
ui::WindowShowState state = ui::SHOW_STATE_NORMAL;
......@@ -177,7 +243,7 @@ TEST_F(AppWindowGeometryCacheTest, CorruptBounds) {
// Test corrupt screen bounds will not be loaded.
TEST_F(AppWindowGeometryCacheTest, CorruptScreenBounds) {
const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1");
const std::string extension_id = AddExtensionWithPrefs("ext1");
gfx::Rect bounds(4, 5, 31, 43);
gfx::Rect screen_bounds;
ui::WindowShowState state = ui::SHOW_STATE_NORMAL;
......@@ -195,7 +261,7 @@ TEST_F(AppWindowGeometryCacheTest, CorruptScreenBounds) {
// Test corrupt state will not be loaded.
TEST_F(AppWindowGeometryCacheTest, CorruptState) {
const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1");
const std::string extension_id = AddExtensionWithPrefs("ext1");
gfx::Rect bounds(4, 5, 31, 43);
gfx::Rect screen_bounds(0, 0, 1600, 900);
ui::WindowShowState state = ui::SHOW_STATE_DEFAULT;
......@@ -214,7 +280,7 @@ TEST_F(AppWindowGeometryCacheTest, CorruptState) {
// Test saving geometry, screen_bounds and state to the cache and state store,
// and reading it back.
TEST_F(AppWindowGeometryCacheTest, SaveGeometryAndStateToStore) {
const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1");
const std::string extension_id = AddExtensionWithPrefs("ext1");
const std::string window_id(kWindowId);
// inform cache of extension
......@@ -241,7 +307,7 @@ TEST_F(AppWindowGeometryCacheTest, SaveGeometryAndStateToStore) {
// check if geometry got stored correctly in the state store
const base::DictionaryValue* dict =
prefs_->prefs()->GetGeometryCache(extension_id);
extension_prefs_->GetGeometryCache(extension_id);
ASSERT_TRUE(dict);
ASSERT_TRUE(dict->HasKey(window_id));
......@@ -281,7 +347,7 @@ TEST_F(AppWindowGeometryCacheTest, NoDuplicateWrites) {
using testing::_;
using testing::Mock;
const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1");
const std::string extension_id = AddExtensionWithPrefs("ext1");
gfx::Rect bounds1(100, 200, 300, 400);
gfx::Rect bounds2(200, 400, 600, 800);
gfx::Rect bounds2_duplicate(200, 400, 600, 800);
......@@ -290,9 +356,9 @@ TEST_F(AppWindowGeometryCacheTest, NoDuplicateWrites) {
gfx::Rect screen_bounds2(0, 0, 1366, 768);
gfx::Rect screen_bounds2_duplicate(0, 0, 1366, 768);
MockPrefChangeCallback observer(prefs_->pref_service());
MockPrefChangeCallback observer(pref_service_.get());
PrefChangeRegistrar registrar;
registrar.Init(prefs_->pref_service());
registrar.Init(pref_service_.get());
registrar.Add("extensions.settings", observer.GetCallback());
// Write the first bounds - it should do > 0 writes.
......@@ -340,7 +406,7 @@ TEST_F(AppWindowGeometryCacheTest, NoDuplicateWrites) {
// Tests that no more than kMaxCachedWindows windows will be cached.
TEST_F(AppWindowGeometryCacheTest, MaxWindows) {
const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1");
const std::string extension_id = AddExtensionWithPrefs("ext1");
// inform cache of extension
LoadExtension(extension_id);
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "extensions/shell/browser/shell_app_sorting.h"
#include "extensions/browser/null_app_sorting.h"
#include "sync/api/string_ordinal.h"
......@@ -17,89 +17,89 @@ const char kFirstPage[] = "a";
namespace extensions {
ShellAppSorting::ShellAppSorting() {
NullAppSorting::NullAppSorting() {
}
ShellAppSorting::~ShellAppSorting() {
NullAppSorting::~NullAppSorting() {
}
void ShellAppSorting::SetExtensionScopedPrefs(ExtensionScopedPrefs* prefs) {
void NullAppSorting::SetExtensionScopedPrefs(ExtensionScopedPrefs* prefs) {
}
void ShellAppSorting::SetExtensionSyncService(
void NullAppSorting::SetExtensionSyncService(
ExtensionSyncService* extension_sync_service) {
}
void ShellAppSorting::Initialize(const ExtensionIdList& extension_ids) {
void NullAppSorting::Initialize(const ExtensionIdList& extension_ids) {
}
void ShellAppSorting::FixNTPOrdinalCollisions() {
void NullAppSorting::FixNTPOrdinalCollisions() {
}
void ShellAppSorting::EnsureValidOrdinals(
void NullAppSorting::EnsureValidOrdinals(
const std::string& extension_id,
const syncer::StringOrdinal& suggested_page) {
}
void ShellAppSorting::OnExtensionMoved(
void NullAppSorting::OnExtensionMoved(
const std::string& moved_extension_id,
const std::string& predecessor_extension_id,
const std::string& successor_extension_id) {
}
syncer::StringOrdinal ShellAppSorting::GetAppLaunchOrdinal(
syncer::StringOrdinal NullAppSorting::GetAppLaunchOrdinal(
const std::string& extension_id) const {
return syncer::StringOrdinal(kFirstApp);
}
void ShellAppSorting::SetAppLaunchOrdinal(
void NullAppSorting::SetAppLaunchOrdinal(
const std::string& extension_id,
const syncer::StringOrdinal& new_app_launch_ordinal) {
}
syncer::StringOrdinal ShellAppSorting::CreateFirstAppLaunchOrdinal(
syncer::StringOrdinal NullAppSorting::CreateFirstAppLaunchOrdinal(
const syncer::StringOrdinal& page_ordinal) const {
return syncer::StringOrdinal(kFirstApp);
}
syncer::StringOrdinal ShellAppSorting::CreateNextAppLaunchOrdinal(
syncer::StringOrdinal NullAppSorting::CreateNextAppLaunchOrdinal(
const syncer::StringOrdinal& page_ordinal) const {
return syncer::StringOrdinal(kNextApp);
}
syncer::StringOrdinal ShellAppSorting::CreateFirstAppPageOrdinal() const {
syncer::StringOrdinal NullAppSorting::CreateFirstAppPageOrdinal() const {
return syncer::StringOrdinal(kFirstPage);
}
syncer::StringOrdinal ShellAppSorting::GetNaturalAppPageOrdinal() const {
syncer::StringOrdinal NullAppSorting::GetNaturalAppPageOrdinal() const {
return syncer::StringOrdinal(kFirstPage);
}
syncer::StringOrdinal ShellAppSorting::GetPageOrdinal(
syncer::StringOrdinal NullAppSorting::GetPageOrdinal(
const std::string& extension_id) const {
return syncer::StringOrdinal(kFirstPage);
}
void ShellAppSorting::SetPageOrdinal(
void NullAppSorting::SetPageOrdinal(
const std::string& extension_id,
const syncer::StringOrdinal& new_page_ordinal) {
}
void ShellAppSorting::ClearOrdinals(const std::string& extension_id) {
void NullAppSorting::ClearOrdinals(const std::string& extension_id) {
}
int ShellAppSorting::PageStringOrdinalAsInteger(
int NullAppSorting::PageStringOrdinalAsInteger(
const syncer::StringOrdinal& page_ordinal) const {
return 0;
}
syncer::StringOrdinal ShellAppSorting::PageIntegerAsStringOrdinal(
syncer::StringOrdinal NullAppSorting::PageIntegerAsStringOrdinal(
size_t page_index) {
return syncer::StringOrdinal(kFirstPage);
}
void ShellAppSorting::SetExtensionVisible(const std::string& extension_id,
bool visible) {
void NullAppSorting::SetExtensionVisible(const std::string& extension_id,
bool visible) {
}
} // namespace extensions
......@@ -2,20 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef EXTENSIONS_SHELL_BROWSER_SHELL_APP_SORTING_H_
#define EXTENSIONS_SHELL_BROWSER_SHELL_APP_SORTING_H_
#ifndef EXTENSIONS_BROWSER_NULL_APP_SORTING_H_
#define EXTENSIONS_BROWSER_NULL_APP_SORTING_H_
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "extensions/browser/app_sorting.h"
namespace extensions {
// A stub AppSorting. Since app_shell only runs a single app we don't need to
// sort them.
class ShellAppSorting : public AppSorting {
// An AppSorting that doesn't provide any ordering.
class NullAppSorting : public AppSorting {
public:
ShellAppSorting();
virtual ~ShellAppSorting();
NullAppSorting();
virtual ~NullAppSorting();
// AppSorting overrides:
virtual void SetExtensionScopedPrefs(ExtensionScopedPrefs* prefs) OVERRIDE;
......@@ -55,9 +55,9 @@ class ShellAppSorting : public AppSorting {
bool visible) OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(ShellAppSorting);
DISALLOW_COPY_AND_ASSIGN(NullAppSorting);
};
} // namespace extensions
#endif // EXTENSIONS_SHELL_BROWSER_SHELL_APP_SORTING_H_
#endif // EXTENSIONS_BROWSER_NULL_APP_SORTING_H_
......@@ -597,6 +597,8 @@
'browser/management_policy.cc',
'browser/management_policy.h',
'browser/notification_types.h',
'browser/null_app_sorting.cc',
'browser/null_app_sorting.h',
'browser/pref_names.cc',
'browser/pref_names.h',
'browser/process_manager.cc',
......@@ -977,6 +979,7 @@
'../base/base.gyp:base_prefs_test_support',
'../base/base.gyp:test_support_base',
'../components/components.gyp:keyed_service_content',
'../components/components.gyp:user_prefs',
'../content/content_shell_and_tests.gyp:test_support_content',
'../device/bluetooth/bluetooth.gyp:device_bluetooth_mocks',
'../device/serial/serial.gyp:device_serial',
......@@ -1011,6 +1014,7 @@
'browser/api/storage/settings_quota_unittest.cc',
'browser/api/storage/storage_api_unittest.cc',
'browser/api/storage/storage_frontend_unittest.cc',
'browser/app_window/app_window_geometry_cache_unittest.cc',
'browser/computed_hashes_unittest.cc',
'browser/content_hash_tree_unittest.cc',
'browser/event_listener_map_unittest.cc',
......
......@@ -58,8 +58,6 @@
'browser/media_capture_util.h',
'browser/shell_app_delegate.cc',
'browser/shell_app_delegate.h',
'browser/shell_app_sorting.cc',
'browser/shell_app_sorting.h',
'browser/shell_app_window.cc',
'browser/shell_app_window.h',
'browser/shell_app_window_controller.h',
......
......@@ -16,8 +16,8 @@
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_function_registry.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/null_app_sorting.h"
#include "extensions/shell/browser/api/generated_api_registration.h"
#include "extensions/shell/browser/shell_app_sorting.h"
#include "extensions/shell/browser/shell_extension_host_delegate.h"
#include "extensions/shell/browser/shell_extension_system_factory.h"
#include "extensions/shell/browser/shell_runtime_api_delegate.h"
......@@ -161,7 +161,7 @@ void ShellExtensionsBrowserClient::PermitExternalProtocolHandler() {
}
scoped_ptr<AppSorting> ShellExtensionsBrowserClient::CreateAppSorting() {
return scoped_ptr<AppSorting>(new ShellAppSorting);
return scoped_ptr<AppSorting>(new NullAppSorting);
}
bool ShellExtensionsBrowserClient::IsRunningInForcedAppMode() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment