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

Unified Diff: ios/web/web_state/page_display_state_unittest.mm

Issue 2664113003: Moved serialization out of CRWSessionEntry. (Closed)
Patch Set: Eugene's comments Created 3 years, 11 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 | « ios/web/public/web_state/page_display_state.mm ('k') | ios/web/web_state/ui/crw_web_controller.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/web/web_state/page_display_state_unittest.mm
diff --git a/ios/web/web_state/page_display_state_unittest.mm b/ios/web/web_state/page_display_state_unittest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..ac9c73a89f0cf4275a899d82c1f500d136f91b96
--- /dev/null
+++ b/ios/web/web_state/page_display_state_unittest.mm
@@ -0,0 +1,65 @@
+// Copyright 2017 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.
+
+#import "ios/web/public/web_state/page_display_state.h"
+
+#import "base/mac/scoped_nsobject.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+#define EXPECT_NAN(value) EXPECT_NE(value, value)
+
+// Tests that the empty constructor creates an invalid PageDisplayState with all
+// NAN values.
+TEST(PageDisplayStateTest, EmptyConstructor) {
+ web::PageDisplayState state;
+ EXPECT_NAN(state.scroll_state().offset_x());
+ EXPECT_NAN(state.scroll_state().offset_y());
+ EXPECT_NAN(state.zoom_state().minimum_zoom_scale());
+ EXPECT_NAN(state.zoom_state().maximum_zoom_scale());
+ EXPECT_NAN(state.zoom_state().zoom_scale());
+ EXPECT_FALSE(state.IsValid());
+}
+
+// Tests that the constructor with input states correctly populates the display
+// state.
+TEST(PageDisplayStateTest, StatesConstructor) {
+ web::PageScrollState scroll_state(0.0, 1.0);
+ EXPECT_EQ(0.0, scroll_state.offset_x());
+ EXPECT_EQ(1.0, scroll_state.offset_y());
+ EXPECT_TRUE(scroll_state.IsValid());
+ web::PageZoomState zoom_state(1.0, 5.0, 1.0);
+ EXPECT_EQ(1.0, zoom_state.minimum_zoom_scale());
+ EXPECT_EQ(5.0, zoom_state.maximum_zoom_scale());
+ EXPECT_EQ(1.0, zoom_state.zoom_scale());
+ EXPECT_TRUE(zoom_state.IsValid());
+ web::PageDisplayState state(scroll_state, zoom_state);
+ EXPECT_EQ(scroll_state.offset_x(), state.scroll_state().offset_x());
+ EXPECT_EQ(scroll_state.offset_y(), state.scroll_state().offset_y());
+ EXPECT_EQ(zoom_state.minimum_zoom_scale(),
+ state.zoom_state().minimum_zoom_scale());
+ EXPECT_EQ(zoom_state.maximum_zoom_scale(),
+ state.zoom_state().maximum_zoom_scale());
+ EXPECT_EQ(zoom_state.zoom_scale(), state.zoom_state().zoom_scale());
+ EXPECT_TRUE(state.IsValid());
+}
+
+// Tests the constructor with value inputs.
+TEST(PageDisplayStateTest, ValuesConstructor) {
+ web::PageDisplayState state(0.0, 1.0, 1.0, 5.0, 1.0);
+ EXPECT_EQ(0.0, state.scroll_state().offset_x());
+ EXPECT_EQ(1.0, state.scroll_state().offset_y());
+ EXPECT_EQ(1.0, state.zoom_state().minimum_zoom_scale());
+ EXPECT_EQ(5.0, state.zoom_state().maximum_zoom_scale());
+ EXPECT_EQ(1.0, state.zoom_state().zoom_scale());
+ EXPECT_TRUE(state.IsValid());
+}
+
+// Tests converting between a PageDisplayState, its serialization, and back.
+TEST(PageDisplayStateTest, Serialization) {
+ web::PageDisplayState state(0.0, 1.0, 1.0, 5.0, 1.0);
+ base::scoped_nsobject<NSDictionary> serialization(
+ [state.GetSerialization() retain]);
+ web::PageDisplayState new_state(serialization);
+ EXPECT_EQ(state, new_state);
+}
« no previous file with comments | « ios/web/public/web_state/page_display_state.mm ('k') | ios/web/web_state/ui/crw_web_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698