| Index: chrome/browser/extensions/shell_window_geometry_cache_unittest.cc
|
| diff --git a/chrome/browser/extensions/shell_window_geometry_cache_unittest.cc b/chrome/browser/extensions/shell_window_geometry_cache_unittest.cc
|
| index e349da8244273a1c10e60152629ba69e235f6fb5..3f079be82efd8232e024f9d89632a16f960dd7b4 100644
|
| --- a/chrome/browser/extensions/shell_window_geometry_cache_unittest.cc
|
| +++ b/chrome/browser/extensions/shell_window_geometry_cache_unittest.cc
|
| @@ -36,9 +36,11 @@ class ShellWindowGeometryCacheTest : public testing::Test {
|
| cache_->SetSyncDelayForTests(0);
|
| }
|
|
|
| - void AddGeometryAndLoadExtension(const std::string& extension_id,
|
| - const std::string& window_id,
|
| - const gfx::Rect& bounds);
|
| + void AddGeometryAndLoadExtension(
|
| + const std::string& extension_id,
|
| + const std::string& window_id,
|
| + const gfx::Rect& bounds,
|
| + ui::WindowShowState state);
|
|
|
| // Spins the UI threads' message loops to make sure any task
|
| // posted to sync the geometry to the value store gets a chance to run.
|
| @@ -56,14 +58,17 @@ class ShellWindowGeometryCacheTest : public testing::Test {
|
| };
|
|
|
| void ShellWindowGeometryCacheTest::AddGeometryAndLoadExtension(
|
| - const std::string& extension_id, const std::string& window_id,
|
| - const gfx::Rect& bounds) {
|
| + const std::string& extension_id,
|
| + const std::string& window_id,
|
| + const gfx::Rect& bounds,
|
| + ui::WindowShowState state) {
|
| scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
|
| base::DictionaryValue* value = new base::DictionaryValue;
|
| value->SetInteger("x", bounds.x());
|
| value->SetInteger("y", bounds.y());
|
| value->SetInteger("w", bounds.width());
|
| value->SetInteger("h", bounds.height());
|
| + value->SetInteger("state", state);
|
| dict->SetWithoutPathExpansion(window_id, value);
|
| prefs_->prefs()->SetGeometryCache(extension_id, dict.Pass());
|
| LoadExtension(extension_id);
|
| @@ -89,7 +94,7 @@ void ShellWindowGeometryCacheTest::UnloadExtension(
|
| TEST_F(ShellWindowGeometryCacheTest, GetGeometryEmptyStore) {
|
| const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1");
|
| gfx::Rect bounds;
|
| - ASSERT_FALSE(cache_->GetGeometry(extension_id, kWindowId, &bounds));
|
| + ASSERT_FALSE(cache_->GetGeometry(extension_id, kWindowId, &bounds, NULL));
|
| }
|
|
|
| // Test getting geometry for an unknown extension.
|
| @@ -97,32 +102,39 @@ TEST_F(ShellWindowGeometryCacheTest, GetGeometryUnkownExtension) {
|
| const std::string extension_id1 = prefs_->AddExtensionAndReturnId("ext1");
|
| const std::string extension_id2 = prefs_->AddExtensionAndReturnId("ext2");
|
| AddGeometryAndLoadExtension(extension_id1, kWindowId,
|
| - gfx::Rect(4, 5, 31, 43));
|
| + gfx::Rect(4, 5, 31, 43),
|
| + ui::SHOW_STATE_DEFAULT);
|
| gfx::Rect bounds;
|
| - ASSERT_FALSE(cache_->GetGeometry(extension_id2, kWindowId, &bounds));
|
| + ASSERT_FALSE(cache_->GetGeometry(extension_id2, kWindowId, &bounds, NULL));
|
| }
|
|
|
| // Test getting geometry for an unknown window in a known extension.
|
| TEST_F(ShellWindowGeometryCacheTest, GetGeometryUnkownWindow) {
|
| const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1");
|
| AddGeometryAndLoadExtension(extension_id, kWindowId,
|
| - gfx::Rect(4, 5, 31, 43));
|
| + gfx::Rect(4, 5, 31, 43),
|
| + ui::SHOW_STATE_DEFAULT);
|
| gfx::Rect bounds;
|
| - ASSERT_FALSE(cache_->GetGeometry(extension_id, kWindowId2, &bounds));
|
| + ASSERT_FALSE(cache_->GetGeometry(extension_id, kWindowId2, &bounds, NULL));
|
| }
|
|
|
| -// Test that loading geometry from the store works correctly.
|
| -TEST_F(ShellWindowGeometryCacheTest, GetGeometryFromStore) {
|
| +// Test that loading geometry and state from the store works correctly.
|
| +TEST_F(ShellWindowGeometryCacheTest, GetGeometryAndStateFromStore) {
|
| const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1");
|
| gfx::Rect bounds(4, 5, 31, 43);
|
| - AddGeometryAndLoadExtension(extension_id, kWindowId, bounds);
|
| - gfx::Rect newBounds;
|
| - ASSERT_TRUE(cache_->GetGeometry(extension_id, kWindowId, &newBounds));
|
| - ASSERT_EQ(bounds, newBounds);
|
| + ui::WindowShowState state = ui::SHOW_STATE_NORMAL;
|
| + AddGeometryAndLoadExtension(extension_id, kWindowId, bounds, state);
|
| + gfx::Rect new_bounds;
|
| + ui::WindowShowState new_state = ui::SHOW_STATE_DEFAULT;
|
| + ASSERT_TRUE(cache_->GetGeometry(
|
| + extension_id, kWindowId, &new_bounds, &new_state));
|
| + ASSERT_EQ(bounds, new_bounds);
|
| + ASSERT_EQ(state, new_state);
|
| }
|
|
|
| -// Test saving geometry to the cache and state store, and reading it back.
|
| -TEST_F(ShellWindowGeometryCacheTest, SaveGeometryToStore) {
|
| +// Test saving geometry and state to the cache and state store, and reading
|
| +// it back.
|
| +TEST_F(ShellWindowGeometryCacheTest, SaveGeometryAndStateToStore) {
|
| const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1");
|
| const std::string window_id(kWindowId);
|
|
|
| @@ -131,12 +143,16 @@ TEST_F(ShellWindowGeometryCacheTest, SaveGeometryToStore) {
|
|
|
| // update geometry stored in cache
|
| gfx::Rect bounds(4, 5, 31, 43);
|
| - gfx::Rect newBounds;
|
| - cache_->SaveGeometry(extension_id, window_id, bounds);
|
| + ui::WindowShowState state = ui::SHOW_STATE_NORMAL;
|
| + cache_->SaveGeometry(extension_id, window_id, bounds, state);
|
|
|
| // make sure that immediately reading back geometry works
|
| - ASSERT_TRUE(cache_->GetGeometry(extension_id, window_id, &newBounds));
|
| - ASSERT_EQ(bounds, newBounds);
|
| + gfx::Rect new_bounds;
|
| + ui::WindowShowState new_state = ui::SHOW_STATE_DEFAULT;
|
| + ASSERT_TRUE(cache_->GetGeometry(
|
| + extension_id, window_id, &new_bounds, &new_state));
|
| + ASSERT_EQ(bounds, new_bounds);
|
| + ASSERT_EQ(state, new_state);
|
|
|
| // unload extension to force cache to save data to the state store
|
| UnloadExtension(extension_id);
|
| @@ -156,15 +172,20 @@ TEST_F(ShellWindowGeometryCacheTest, SaveGeometryToStore) {
|
| ASSERT_EQ(bounds.width(), v);
|
| ASSERT_TRUE(dict->GetInteger(window_id + ".h", &v));
|
| ASSERT_EQ(bounds.height(), v);
|
| + ASSERT_TRUE(dict->GetInteger(window_id + ".state", &v));
|
| + ASSERT_EQ(state, v);
|
|
|
| // check to make sure cache indeed doesn't know about this extension anymore
|
| - ASSERT_FALSE(cache_->GetGeometry(extension_id, window_id, &newBounds));
|
| + ASSERT_FALSE(cache_->GetGeometry(
|
| + extension_id, window_id, &new_bounds, &new_state));
|
|
|
| // reload extension
|
| LoadExtension(extension_id);
|
| // and make sure the geometry got reloaded properly too
|
| - ASSERT_TRUE(cache_->GetGeometry(extension_id, window_id, &newBounds));
|
| - ASSERT_EQ(bounds, newBounds);
|
| + ASSERT_TRUE(cache_->GetGeometry(
|
| + extension_id, window_id, &new_bounds, &new_state));
|
| + ASSERT_EQ(bounds, new_bounds);
|
| + ASSERT_EQ(state, new_state);
|
| }
|
|
|
| // Tests that we won't do writes to the state store for SaveGeometry calls
|
| @@ -185,20 +206,30 @@ TEST_F(ShellWindowGeometryCacheTest, NoDuplicateWrites) {
|
|
|
| // Write the first bounds - it should do > 0 writes.
|
| EXPECT_CALL(observer, OnPreferenceChanged(_));
|
| - cache_->SaveGeometry(extension_id, kWindowId, bounds1);
|
| + cache_->SaveGeometry(extension_id, kWindowId, bounds1,
|
| + ui::SHOW_STATE_DEFAULT);
|
| WaitForSync();
|
| Mock::VerifyAndClearExpectations(&observer);
|
|
|
| // Write a different bounds - it should also do > 0 writes.
|
| EXPECT_CALL(observer, OnPreferenceChanged(_));
|
| - cache_->SaveGeometry(extension_id, kWindowId, bounds2);
|
| + cache_->SaveGeometry(extension_id, kWindowId, bounds2,
|
| + ui::SHOW_STATE_DEFAULT);
|
| WaitForSync();
|
| Mock::VerifyAndClearExpectations(&observer);
|
|
|
| - // Write a bounds that's a duplicate of what we already have. This should
|
| - // not do any writes.
|
| + // Write a different state - it should also do > 0 writes.
|
| + EXPECT_CALL(observer, OnPreferenceChanged(_));
|
| + cache_->SaveGeometry(extension_id, kWindowId, bounds2,
|
| + ui::SHOW_STATE_NORMAL);
|
| + WaitForSync();
|
| + Mock::VerifyAndClearExpectations(&observer);
|
| +
|
| + // Write a bounds and state that's a duplicate of what we already have.
|
| + // This should not do any writes.
|
| EXPECT_CALL(observer, OnPreferenceChanged(_)).Times(0);
|
| - cache_->SaveGeometry(extension_id, kWindowId, bounds2_duplicate);
|
| + cache_->SaveGeometry(extension_id, kWindowId, bounds2_duplicate,
|
| + ui::SHOW_STATE_NORMAL);
|
| WaitForSync();
|
| Mock::VerifyAndClearExpectations(&observer);
|
| }
|
| @@ -212,15 +243,16 @@ TEST_F(ShellWindowGeometryCacheTest, MaxWindows) {
|
| gfx::Rect bounds(4, 5, 31, 43);
|
| for (size_t i = 0; i < ShellWindowGeometryCache::kMaxCachedWindows + 1; ++i) {
|
| std::string window_id = "window_" + base::IntToString(i);
|
| - cache_->SaveGeometry(extension_id, window_id, bounds);
|
| + cache_->SaveGeometry(extension_id, window_id, bounds,
|
| + ui::SHOW_STATE_DEFAULT);
|
| }
|
|
|
| // The first added window should no longer have cached geometry.
|
| - EXPECT_FALSE(cache_->GetGeometry(extension_id, "window_0", &bounds));
|
| + EXPECT_FALSE(cache_->GetGeometry(extension_id, "window_0", &bounds, NULL));
|
| // All other windows should still exist.
|
| for (size_t i = 1; i < ShellWindowGeometryCache::kMaxCachedWindows + 1; ++i) {
|
| std::string window_id = "window_" + base::IntToString(i);
|
| - EXPECT_TRUE(cache_->GetGeometry(extension_id, window_id, &bounds));
|
| + EXPECT_TRUE(cache_->GetGeometry(extension_id, window_id, &bounds, NULL));
|
| }
|
| }
|
|
|
|
|