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

Side by Side Diff: ios/web/history_state_util_unittest.mm

Issue 988383002: Upstream various ios/web utilities and helpers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@web-public-upstreaming
Patch Set: Created 5 years, 9 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2012 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 <Foundation/Foundation.h>
Eugene But (OOO till 7-30) 2015/03/09 16:17:43 Optional: No need for this include
6
7 #import "ios/web/history_state_util.h"
Eugene But (OOO till 7-30) 2015/03/09 16:17:43 Optional: space after this
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "testing/gtest_mac.h"
10 #include "url/gurl.h"
11
12 namespace web {
13 namespace {
14 struct TestEntry {
15 std::string fromUrl;
16 std::string toUrl;
17 std::string expectedUrl;
18 };
19
20 class HistoryStateUtilTest : public ::testing::Test {
21 protected:
22 static const struct TestEntry tests_[];
23 };
24
25 const struct TestEntry HistoryStateUtilTest::tests_[] = {
26 // Valid absolute changes.
27 { "http://foo.com", "http://foo.com/bar", "http://foo.com/bar" },
28 { "https://foo.com", "https://foo.com/bar", "https://foo.com/bar" },
29 { "http://foo.com/", "http://foo.com#bar", "http://foo.com#bar" },
30 { "http://foo.com:80", "http://foo.com:80/b", "http://foo.com:80/b"},
31 { "http://foo.com:888", "http://foo.com:888/b", "http://foo.com:888/b"},
32 // Valid relative changes.
33 { "http://foo.com", "#bar", "http://foo.com#bar" },
34 { "http://foo.com/", "#bar", "http://foo.com/#bar" },
35 { "https://foo.com/", "bar", "https://foo.com/bar" },
36 { "http://foo.com/foo/1", "/bar", "http://foo.com/bar" },
37 { "http://foo.com/foo/1", "bar", "http://foo.com/foo/bar" },
38 { "http://foo.com/", "bar.com", "http://foo.com/bar.com" },
39 { "http://foo.com", "bar.com", "http://foo.com/bar.com" },
40 { "http://foo.com:888", "bar.com", "http://foo.com:888/bar.com" },
41 // Invalid scheme changes.
42 { "http://foo.com", "https://foo.com#bar", "" },
43 { "https://foo.com", "http://foo.com#bar", "" },
44 // Invalid domain changes.
45 { "http://foo.com/bar", "http://bar.com", "" },
46 { "http://foo.com/bar", "http://www.foo.com/bar2", "" },
47 // Valid port change.
48 { "http://foo.com", "http://foo.com:80/bar", "http://foo.com/bar" },
49 { "http://foo.com:80", "http://foo.com/bar", "http://foo.com/bar" },
50 // Invalid port change.
51 { "http://foo.com", "http://foo.com:42/bar", "" },
52 { "http://foo.com:42", "http://foo.com/bar", "" },
53 // Invalid URL.
54 { "http://foo.com", "http://fo o.c om/ba r", "" },
55 { "http://foo.com:80", "bar", "http://foo.com:80/bar" }
56 };
57
58 TEST_F(HistoryStateUtilTest, TestIsHistoryStateChangeValid) {
59 for (size_t i = 0; i < arraysize(tests_); ++i) {
60 GURL fromUrl(tests_[i].fromUrl);
61 GURL toUrl = history_state_util::GetHistoryStateChangeUrl(fromUrl, fromUrl,
62 tests_[i].toUrl);
63 bool expected_result = tests_[i].expectedUrl.size() > 0;
64 bool actual_result = toUrl.is_valid();
65 if (actual_result) {
66 actual_result = history_state_util::IsHistoryStateChangeValid(fromUrl,
67 toUrl);
68 }
69 EXPECT_EQ(expected_result, actual_result) << tests_[i].fromUrl << " "
70 << tests_[i].toUrl;
71 }
72 }
73
74 TEST_F(HistoryStateUtilTest, TestGetHistoryStateChangeUrl) {
75 for (size_t i = 0; i < arraysize(tests_); ++i) {
76 GURL fromUrl(tests_[i].fromUrl);
77 GURL expectedResult(tests_[i].expectedUrl);
78 GURL actualResult = history_state_util::GetHistoryStateChangeUrl(
79 fromUrl, fromUrl, tests_[i].toUrl);
80 EXPECT_EQ(expectedResult, actualResult);
81 }
82 }
83
84 // Ensures that the baseUrl is used to resolve the destination, not currentUrl.
85 TEST_F(HistoryStateUtilTest, TestGetHistoryStateChangeUrlWithBase) {
86 GURL fromUrl("http://foo.com/relative/path");
87 GURL baseUrl("http://foo.com");
88 std::string destination = "bar";
89
90 GURL result = history_state_util::GetHistoryStateChangeUrl(fromUrl, baseUrl,
91 destination);
92 EXPECT_TRUE(result.is_valid());
93 EXPECT_EQ(GURL("http://foo.com/bar"), result);
94 }
95
96 // Ensures that an invalid baseUrl gracefully returns an invalid destination.
97 TEST_F(HistoryStateUtilTest, TestGetHistoryStateChangeUrlWithInvalidBase) {
98 GURL fromUrl("http://foo.com");
99 GURL baseUrl("http://not a url");
100 std::string destination = "baz";
101
102 GURL result = history_state_util::GetHistoryStateChangeUrl(fromUrl, baseUrl,
103 destination);
104 EXPECT_FALSE(result.is_valid());
105 }
106
107 } // anonymous namespace
108 } // namespace web
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698