OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "ios/web/public/web_state/page_display_state.h" |
| 6 |
| 7 #import "base/mac/scoped_nsobject.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 |
| 10 #define EXPECT_NAN(value) EXPECT_NE(value, value) |
| 11 |
| 12 // Tests that the empty constructor creates an invalid PageDisplayState with all |
| 13 // NAN values. |
| 14 TEST(PageDisplayStateTest, EmptyConstructor) { |
| 15 web::PageDisplayState state; |
| 16 EXPECT_NAN(state.scroll_state().offset_x()); |
| 17 EXPECT_NAN(state.scroll_state().offset_y()); |
| 18 EXPECT_NAN(state.zoom_state().minimum_zoom_scale()); |
| 19 EXPECT_NAN(state.zoom_state().maximum_zoom_scale()); |
| 20 EXPECT_NAN(state.zoom_state().zoom_scale()); |
| 21 EXPECT_FALSE(state.IsValid()); |
| 22 } |
| 23 |
| 24 // Tests that the constructor with input states correctly populates the display |
| 25 // state. |
| 26 TEST(PageDisplayStateTest, StatesConstructor) { |
| 27 web::PageScrollState scroll_state(0.0, 1.0); |
| 28 EXPECT_EQ(0.0, scroll_state.offset_x()); |
| 29 EXPECT_EQ(1.0, scroll_state.offset_y()); |
| 30 EXPECT_TRUE(scroll_state.IsValid()); |
| 31 web::PageZoomState zoom_state(1.0, 5.0, 1.0); |
| 32 EXPECT_EQ(1.0, zoom_state.minimum_zoom_scale()); |
| 33 EXPECT_EQ(5.0, zoom_state.maximum_zoom_scale()); |
| 34 EXPECT_EQ(1.0, zoom_state.zoom_scale()); |
| 35 EXPECT_TRUE(zoom_state.IsValid()); |
| 36 web::PageDisplayState state(scroll_state, zoom_state); |
| 37 EXPECT_EQ(scroll_state.offset_x(), state.scroll_state().offset_x()); |
| 38 EXPECT_EQ(scroll_state.offset_y(), state.scroll_state().offset_y()); |
| 39 EXPECT_EQ(zoom_state.minimum_zoom_scale(), |
| 40 state.zoom_state().minimum_zoom_scale()); |
| 41 EXPECT_EQ(zoom_state.maximum_zoom_scale(), |
| 42 state.zoom_state().maximum_zoom_scale()); |
| 43 EXPECT_EQ(zoom_state.zoom_scale(), state.zoom_state().zoom_scale()); |
| 44 EXPECT_TRUE(state.IsValid()); |
| 45 } |
| 46 |
| 47 // Tests the constructor with value inputs. |
| 48 TEST(PageDisplayStateTest, ValuesConstructor) { |
| 49 web::PageDisplayState state(0.0, 1.0, 1.0, 5.0, 1.0); |
| 50 EXPECT_EQ(0.0, state.scroll_state().offset_x()); |
| 51 EXPECT_EQ(1.0, state.scroll_state().offset_y()); |
| 52 EXPECT_EQ(1.0, state.zoom_state().minimum_zoom_scale()); |
| 53 EXPECT_EQ(5.0, state.zoom_state().maximum_zoom_scale()); |
| 54 EXPECT_EQ(1.0, state.zoom_state().zoom_scale()); |
| 55 EXPECT_TRUE(state.IsValid()); |
| 56 } |
| 57 |
| 58 // Tests converting between a PageDisplayState, its serialization, and back. |
| 59 TEST(PageDisplayStateTest, Serialization) { |
| 60 web::PageDisplayState state(0.0, 1.0, 1.0, 5.0, 1.0); |
| 61 base::scoped_nsobject<NSDictionary> serialization( |
| 62 [state.GetSerialization() retain]); |
| 63 web::PageDisplayState new_state(serialization); |
| 64 EXPECT_EQ(state, new_state); |
| 65 } |
OLD | NEW |