summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/shell_window_geometry_cache_unittest.cc
diff options
context:
space:
mode:
authorstevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-09 06:10:57 +0000
committerstevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-09 06:10:57 +0000
commit68eeede20e63fbb9a8756ed73e482b87dde57c72 (patch)
tree26d1bd889cbfd7b32131d585a97dcb9b447b8733 /chrome/browser/extensions/shell_window_geometry_cache_unittest.cc
parentc2ff9b4ec2549c5b3b36c11fe2fca7b5495adf9a (diff)
downloadchromium_src-68eeede20e63fbb9a8756ed73e482b87dde57c72.zip
chromium_src-68eeede20e63fbb9a8756ed73e482b87dde57c72.tar.gz
chromium_src-68eeede20e63fbb9a8756ed73e482b87dde57c72.tar.bz2
Save and restore State for ShellWindows, including panels
This replaces ShellWindow::CreateParams::State with ui::WindowShowState for simplicty and consistency with Browser session restore. BUG=233556 TBR=flackr@chromium.org, skuhne@chromium.org, sky@chromium.org Original CL: https://codereview.chromium.org/14031021/ + disabled flakey browser tests on linux Review URL: https://chromiumcodereview.appspot.com/14663010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@199145 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/shell_window_geometry_cache_unittest.cc')
-rw-r--r--chrome/browser/extensions/shell_window_geometry_cache_unittest.cc101
1 files changed, 65 insertions, 36 deletions
diff --git a/chrome/browser/extensions/shell_window_geometry_cache_unittest.cc b/chrome/browser/extensions/shell_window_geometry_cache_unittest.cc
index e349da8..efab64f 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);
@@ -88,8 +93,7 @@ void ShellWindowGeometryCacheTest::UnloadExtension(
// Test getting geometry from an empty store.
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, NULL, NULL));
}
// Test getting geometry for an unknown extension.
@@ -97,32 +101,37 @@ 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 bounds;
- ASSERT_FALSE(cache_->GetGeometry(extension_id2, kWindowId, &bounds));
+ gfx::Rect(4, 5, 31, 43),
+ ui::SHOW_STATE_DEFAULT);
+ ASSERT_FALSE(cache_->GetGeometry(extension_id2, kWindowId, NULL, 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 bounds;
- ASSERT_FALSE(cache_->GetGeometry(extension_id, kWindowId2, &bounds));
+ gfx::Rect(4, 5, 31, 43),
+ ui::SHOW_STATE_DEFAULT);
+ ASSERT_FALSE(cache_->GetGeometry(extension_id, kWindowId2, NULL, 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 +140,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 +169,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 +203,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 +240,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", NULL, 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, NULL, NULL));
}
}