Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1492)

Unified Diff: apps/shell_window_geometry_cache_unittest.cc

Issue 17378003: [WIN]Save work area of window and adjust bounds to ensure it fit on screen before show. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update to windows only. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « apps/shell_window_geometry_cache.cc ('k') | chrome/browser/extensions/platform_app_browsertest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: apps/shell_window_geometry_cache_unittest.cc
diff --git a/apps/shell_window_geometry_cache_unittest.cc b/apps/shell_window_geometry_cache_unittest.cc
index 85ed13714cad99a32aa1f3f2dd79015cad423b9a..7cc3dac25a93fad68c6d10100eaa3017a314a0bd 100644
--- a/apps/shell_window_geometry_cache_unittest.cc
+++ b/apps/shell_window_geometry_cache_unittest.cc
@@ -39,6 +39,7 @@ class ShellWindowGeometryCacheTest : public testing::Test {
const std::string& extension_id,
const std::string& window_id,
const gfx::Rect& bounds,
+ const gfx::Rect& screen_bounds,
ui::WindowShowState state);
// Spins the UI threads' message loops to make sure any task
@@ -60,6 +61,7 @@ void ShellWindowGeometryCacheTest::AddGeometryAndLoadExtension(
const std::string& extension_id,
const std::string& window_id,
const gfx::Rect& bounds,
+ const gfx::Rect& screen_bounds,
ui::WindowShowState state) {
scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
base::DictionaryValue* value = new base::DictionaryValue;
@@ -67,6 +69,10 @@ void ShellWindowGeometryCacheTest::AddGeometryAndLoadExtension(
value->SetInteger("y", bounds.y());
value->SetInteger("w", bounds.width());
value->SetInteger("h", bounds.height());
+ value->SetInteger("screen_bounds_x", screen_bounds.x());
+ value->SetInteger("screen_bounds_y", screen_bounds.y());
+ value->SetInteger("screen_bounds_w", screen_bounds.width());
+ value->SetInteger("screen_bounds_h", screen_bounds.height());
value->SetInteger("state", state);
dict->SetWithoutPathExpansion(window_id, value);
prefs_->prefs()->SetGeometryCache(extension_id, dict.Pass());
@@ -92,7 +98,7 @@ void ShellWindowGeometryCacheTest::UnloadExtension(
// Test getting geometry from an empty store.
TEST_F(ShellWindowGeometryCacheTest, GetGeometryEmptyStore) {
const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1");
- ASSERT_FALSE(cache_->GetGeometry(extension_id, kWindowId, NULL, NULL));
+ ASSERT_FALSE(cache_->GetGeometry(extension_id, kWindowId, NULL, NULL, NULL));
}
// Test getting geometry for an unknown extension.
@@ -101,8 +107,9 @@ TEST_F(ShellWindowGeometryCacheTest, GetGeometryUnkownExtension) {
const std::string extension_id2 = prefs_->AddExtensionAndReturnId("ext2");
AddGeometryAndLoadExtension(extension_id1, kWindowId,
gfx::Rect(4, 5, 31, 43),
+ gfx::Rect(0, 0, 1600, 900),
ui::SHOW_STATE_DEFAULT);
- ASSERT_FALSE(cache_->GetGeometry(extension_id2, kWindowId, NULL, NULL));
+ ASSERT_FALSE(cache_->GetGeometry(extension_id2, kWindowId, NULL, NULL, NULL));
}
// Test getting geometry for an unknown window in a known extension.
@@ -110,26 +117,32 @@ TEST_F(ShellWindowGeometryCacheTest, GetGeometryUnkownWindow) {
const std::string extension_id = prefs_->AddExtensionAndReturnId("ext1");
AddGeometryAndLoadExtension(extension_id, kWindowId,
gfx::Rect(4, 5, 31, 43),
+ gfx::Rect(0, 0, 1600, 900),
ui::SHOW_STATE_DEFAULT);
- ASSERT_FALSE(cache_->GetGeometry(extension_id, kWindowId2, NULL, NULL));
+ ASSERT_FALSE(cache_->GetGeometry(extension_id, kWindowId2, NULL, NULL, NULL));
}
-// Test that loading geometry and state from the store works correctly.
+// Test that loading geometry, screen_bounds 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);
+ gfx::Rect screen_bounds(0, 0, 1600, 900);
ui::WindowShowState state = ui::SHOW_STATE_NORMAL;
- AddGeometryAndLoadExtension(extension_id, kWindowId, bounds, state);
+ AddGeometryAndLoadExtension(extension_id, kWindowId, bounds,
+ screen_bounds, state);
gfx::Rect new_bounds;
+ gfx::Rect new_screen_bounds;
ui::WindowShowState new_state = ui::SHOW_STATE_DEFAULT;
ASSERT_TRUE(cache_->GetGeometry(
- extension_id, kWindowId, &new_bounds, &new_state));
+ extension_id, kWindowId, &new_bounds, &new_screen_bounds, &new_state));
ASSERT_EQ(bounds, new_bounds);
+ ASSERT_EQ(screen_bounds, new_screen_bounds);
ASSERT_EQ(state, new_state);
}
-// Test saving geometry and state to the cache and state store, and reading
-// it back.
+// Test saving geometry, screen_bounds 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);
@@ -139,15 +152,18 @@ TEST_F(ShellWindowGeometryCacheTest, SaveGeometryAndStateToStore) {
// update geometry stored in cache
gfx::Rect bounds(4, 5, 31, 43);
+ gfx::Rect screen_bounds(0, 0, 1600, 900);
ui::WindowShowState state = ui::SHOW_STATE_NORMAL;
- cache_->SaveGeometry(extension_id, window_id, bounds, state);
+ cache_->SaveGeometry(extension_id, window_id, bounds, screen_bounds, state);
// make sure that immediately reading back geometry works
gfx::Rect new_bounds;
+ gfx::Rect new_screen_bounds;
ui::WindowShowState new_state = ui::SHOW_STATE_DEFAULT;
ASSERT_TRUE(cache_->GetGeometry(
- extension_id, window_id, &new_bounds, &new_state));
+ extension_id, window_id, &new_bounds, &new_screen_bounds, &new_state));
ASSERT_EQ(bounds, new_bounds);
+ ASSERT_EQ(screen_bounds, new_screen_bounds);
ASSERT_EQ(state, new_state);
// unload extension to force cache to save data to the state store
@@ -168,6 +184,14 @@ TEST_F(ShellWindowGeometryCacheTest, SaveGeometryAndStateToStore) {
ASSERT_EQ(bounds.width(), v);
ASSERT_TRUE(dict->GetInteger(window_id + ".h", &v));
ASSERT_EQ(bounds.height(), v);
+ ASSERT_TRUE(dict->GetInteger(window_id + ".screen_bounds_x", &v));
+ ASSERT_EQ(screen_bounds.x(), v);
+ ASSERT_TRUE(dict->GetInteger(window_id + ".screen_bounds_y", &v));
+ ASSERT_EQ(screen_bounds.y(), v);
+ ASSERT_TRUE(dict->GetInteger(window_id + ".screen_bounds_w", &v));
+ ASSERT_EQ(screen_bounds.width(), v);
+ ASSERT_TRUE(dict->GetInteger(window_id + ".screen_bounds_h", &v));
+ ASSERT_EQ(screen_bounds.height(), v);
ASSERT_TRUE(dict->GetInteger(window_id + ".state", &v));
ASSERT_EQ(state, v);
@@ -175,8 +199,9 @@ TEST_F(ShellWindowGeometryCacheTest, SaveGeometryAndStateToStore) {
LoadExtension(extension_id);
// and make sure the geometry got reloaded properly too
ASSERT_TRUE(cache_->GetGeometry(
- extension_id, window_id, &new_bounds, &new_state));
+ extension_id, window_id, &new_bounds, &new_screen_bounds, &new_state));
ASSERT_EQ(bounds, new_bounds);
+ ASSERT_EQ(screen_bounds, new_screen_bounds);
ASSERT_EQ(state, new_state);
}
@@ -191,6 +216,10 @@ TEST_F(ShellWindowGeometryCacheTest, NoDuplicateWrites) {
gfx::Rect bounds2(200, 400, 600, 800);
gfx::Rect bounds2_duplicate(200, 400, 600, 800);
+ gfx::Rect screen_bounds1(0, 0, 1600, 900);
+ gfx::Rect screen_bounds2(0, 0, 1366, 768);
+ gfx::Rect screen_bounds2_duplicate(0, 0, 1366, 768);
+
MockPrefChangeCallback observer(prefs_->pref_service());
PrefChangeRegistrar registrar;
registrar.Init(prefs_->pref_service());
@@ -199,29 +228,36 @@ TEST_F(ShellWindowGeometryCacheTest, NoDuplicateWrites) {
// Write the first bounds - it should do > 0 writes.
EXPECT_CALL(observer, OnPreferenceChanged(_));
cache_->SaveGeometry(extension_id, kWindowId, bounds1,
- ui::SHOW_STATE_DEFAULT);
+ screen_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,
- ui::SHOW_STATE_DEFAULT);
+ screen_bounds1, ui::SHOW_STATE_DEFAULT);
+ WaitForSync();
+ Mock::VerifyAndClearExpectations(&observer);
+
+ // Write a different screen bounds - it should also do > 0 writes.
+ EXPECT_CALL(observer, OnPreferenceChanged(_));
+ cache_->SaveGeometry(extension_id, kWindowId, bounds2,
+ screen_bounds2, ui::SHOW_STATE_DEFAULT);
WaitForSync();
Mock::VerifyAndClearExpectations(&observer);
// Write a different state - it should also do > 0 writes.
EXPECT_CALL(observer, OnPreferenceChanged(_));
cache_->SaveGeometry(extension_id, kWindowId, bounds2,
- ui::SHOW_STATE_NORMAL);
+ screen_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.
+ // Write a bounds, screen 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,
- ui::SHOW_STATE_NORMAL);
+ screen_bounds2_duplicate, ui::SHOW_STATE_NORMAL);
WaitForSync();
Mock::VerifyAndClearExpectations(&observer);
}
@@ -233,18 +269,19 @@ TEST_F(ShellWindowGeometryCacheTest, MaxWindows) {
LoadExtension(extension_id);
gfx::Rect bounds(4, 5, 31, 43);
+ gfx::Rect screen_bounds(0, 0, 1600, 900);
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,
- ui::SHOW_STATE_DEFAULT);
+ screen_bounds, ui::SHOW_STATE_DEFAULT);
}
// The first added window should no longer have cached geometry.
- EXPECT_FALSE(cache_->GetGeometry(extension_id, "window_0", NULL, NULL));
+ EXPECT_FALSE(cache_->GetGeometry(extension_id, "window_0", NULL, 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, NULL, NULL));
+ EXPECT_TRUE(cache_->GetGeometry(extension_id, window_id, NULL, NULL, NULL));
}
}
« no previous file with comments | « apps/shell_window_geometry_cache.cc ('k') | chrome/browser/extensions/platform_app_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698