OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ppapi/tests/test_url_util.h" | 5 #include "ppapi/tests/test_url_util.h" |
6 | 6 |
7 #include "ppapi/c/dev/ppb_url_util_dev.h" | 7 #include "ppapi/c/dev/ppb_url_util_dev.h" |
8 #include "ppapi/cpp/dev/url_util_dev.h" | 8 #include "ppapi/cpp/dev/url_util_dev.h" |
9 #include "ppapi/tests/testing_instance.h" | 9 #include "ppapi/tests/testing_instance.h" |
10 | 10 |
11 REGISTER_TEST_CASE(UrlUtil); | 11 REGISTER_TEST_CASE(URLUtil); |
12 | 12 |
13 static bool ComponentEquals(const PP_UrlComponent_Dev& component, | 13 static bool ComponentEquals(const PP_URLComponent_Dev& component, |
14 int begin, int len) { | 14 int begin, int len) { |
15 return component.begin == begin && component.len == len; | 15 return component.begin == begin && component.len == len; |
16 } | 16 } |
17 | 17 |
18 bool TestUrlUtil::Init() { | 18 bool TestURLUtil::Init() { |
19 util_ = pp::UrlUtil_Dev::Get(); | 19 util_ = pp::URLUtil_Dev::Get(); |
20 return !!util_; | 20 return !!util_; |
21 } | 21 } |
22 | 22 |
23 void TestUrlUtil::RunTest() { | 23 void TestURLUtil::RunTest() { |
24 RUN_TEST(Canonicalize); | 24 RUN_TEST(Canonicalize); |
25 RUN_TEST(ResolveRelative); | 25 RUN_TEST(ResolveRelative); |
26 RUN_TEST(IsSameSecurityOrigin); | 26 RUN_TEST(IsSameSecurityOrigin); |
27 RUN_TEST(DocumentCanRequest); | 27 RUN_TEST(DocumentCanRequest); |
28 RUN_TEST(DocumentCanAccessDocument); | 28 RUN_TEST(DocumentCanAccessDocument); |
| 29 RUN_TEST(GetDocumentURL); |
29 } | 30 } |
30 | 31 |
31 std::string TestUrlUtil::TestCanonicalize() { | 32 std::string TestURLUtil::TestCanonicalize() { |
32 // Test no canonicalize output. | 33 // Test no canonicalize output. |
33 pp::Var result = util_->Canonicalize("http://Google.com"); | 34 pp::Var result = util_->Canonicalize("http://Google.com"); |
34 ASSERT_TRUE(result.AsString() == "http://google.com/"); | 35 ASSERT_TRUE(result.AsString() == "http://google.com/"); |
35 | 36 |
36 // Test all the components | 37 // Test all the components |
37 PP_UrlComponents_Dev c; | 38 PP_URLComponents_Dev c; |
38 result = util_->Canonicalize( | 39 result = util_->Canonicalize( |
39 "http://me:pw@Google.com:1234/path?query#ref ", | 40 "http://me:pw@Google.com:1234/path?query#ref ", |
40 &c); | 41 &c); |
41 ASSERT_TRUE(result.AsString() == | 42 ASSERT_TRUE(result.AsString() == |
42 // 0 1 2 3 4 | 43 // 0 1 2 3 4 |
43 // 0123456789012345678901234567890123456789012 | 44 // 0123456789012345678901234567890123456789012 |
44 "http://me:pw@google.com:1234/path?query#ref"); | 45 "http://me:pw@google.com:1234/path?query#ref"); |
45 ASSERT_TRUE(ComponentEquals(c.scheme, 0, 4)); | 46 ASSERT_TRUE(ComponentEquals(c.scheme, 0, 4)); |
46 ASSERT_TRUE(ComponentEquals(c.username, 7, 2)); | 47 ASSERT_TRUE(ComponentEquals(c.username, 7, 2)); |
47 ASSERT_TRUE(ComponentEquals(c.password, 10, 2)); | 48 ASSERT_TRUE(ComponentEquals(c.password, 10, 2)); |
(...skipping 13 matching lines...) Expand all Loading... |
61 ASSERT_TRUE(ComponentEquals(c.password, 0, -1)); | 62 ASSERT_TRUE(ComponentEquals(c.password, 0, -1)); |
62 ASSERT_TRUE(ComponentEquals(c.host, 7, 10)); | 63 ASSERT_TRUE(ComponentEquals(c.host, 7, 10)); |
63 ASSERT_TRUE(ComponentEquals(c.port, 0, -1)); | 64 ASSERT_TRUE(ComponentEquals(c.port, 0, -1)); |
64 ASSERT_TRUE(ComponentEquals(c.path, 17, 1)); | 65 ASSERT_TRUE(ComponentEquals(c.path, 17, 1)); |
65 ASSERT_TRUE(ComponentEquals(c.query, 0, -1)); | 66 ASSERT_TRUE(ComponentEquals(c.query, 0, -1)); |
66 ASSERT_TRUE(ComponentEquals(c.ref, 0, -1)); | 67 ASSERT_TRUE(ComponentEquals(c.ref, 0, -1)); |
67 | 68 |
68 PASS(); | 69 PASS(); |
69 } | 70 } |
70 | 71 |
71 std::string TestUrlUtil::TestResolveRelative() { | 72 std::string TestURLUtil::TestResolveRelative() { |
72 const int kTestCount = 6; | 73 const int kTestCount = 6; |
73 struct TestCase { | 74 struct TestCase { |
74 const char* base; | 75 const char* base; |
75 const char* relative; | 76 const char* relative; |
76 const char* expected; // NULL if | 77 const char* expected; // NULL if |
77 } test_cases[kTestCount] = { | 78 } test_cases[kTestCount] = { |
78 {"http://google.com/", "foo", "http://google.com/foo"}, | 79 {"http://google.com/", "foo", "http://google.com/foo"}, |
79 {"http://google.com/foo", "/bar", "http://google.com/bar"}, | 80 {"http://google.com/foo", "/bar", "http://google.com/bar"}, |
80 {"http://foo/", "http://bar", "http://bar/"}, | 81 {"http://foo/", "http://bar", "http://bar/"}, |
81 {"data:foo", "/bar", NULL}, | 82 {"data:foo", "/bar", NULL}, |
82 {"data:foo", "http://foo/", "http://foo/"}, | 83 {"data:foo", "http://foo/", "http://foo/"}, |
83 {"http://foo/", "", "http://foo/"}, | 84 {"http://foo/", "", "http://foo/"}, |
84 }; | 85 }; |
85 | 86 |
86 for (int i = 0; i < kTestCount; i++) { | 87 for (int i = 0; i < kTestCount; i++) { |
87 pp::Var result = util_->ResolveRelativeToUrl(test_cases[i].base, | 88 pp::Var result = util_->ResolveRelativeToURL(test_cases[i].base, |
88 test_cases[i].relative); | 89 test_cases[i].relative); |
89 if (test_cases[i].expected == NULL) { | 90 if (test_cases[i].expected == NULL) { |
90 ASSERT_TRUE(result.is_null()); | 91 ASSERT_TRUE(result.is_null()); |
91 } else { | 92 } else { |
92 ASSERT_TRUE(result.AsString() == test_cases[i].expected); | 93 ASSERT_TRUE(result.AsString() == test_cases[i].expected); |
93 } | 94 } |
94 } | 95 } |
95 PASS(); | 96 PASS(); |
96 } | 97 } |
97 | 98 |
98 std::string TestUrlUtil::TestIsSameSecurityOrigin() { | 99 std::string TestURLUtil::TestIsSameSecurityOrigin() { |
99 ASSERT_FALSE(util_->IsSameSecurityOrigin("http://google.com/", | 100 ASSERT_FALSE(util_->IsSameSecurityOrigin("http://google.com/", |
100 "http://example.com/")); | 101 "http://example.com/")); |
101 ASSERT_TRUE(util_->IsSameSecurityOrigin("http://google.com/foo", | 102 ASSERT_TRUE(util_->IsSameSecurityOrigin("http://google.com/foo", |
102 "http://google.com/bar")); | 103 "http://google.com/bar")); |
103 PASS(); | 104 PASS(); |
104 } | 105 } |
105 | 106 |
106 std::string TestUrlUtil::TestDocumentCanRequest() { | 107 std::string TestURLUtil::TestDocumentCanRequest() { |
107 // This is hard to test, but we can at least verify we can't request | 108 // This is hard to test, but we can at least verify we can't request |
108 // some random domain. | 109 // some random domain. |
109 ASSERT_FALSE(util_->DocumentCanRequest(*instance_, "http://evil.com/")); | 110 ASSERT_FALSE(util_->DocumentCanRequest(*instance_, "http://evil.com/")); |
110 PASS(); | 111 PASS(); |
111 } | 112 } |
112 | 113 |
113 std::string TestUrlUtil::TestDocumentCanAccessDocument() { | 114 std::string TestURLUtil::TestDocumentCanAccessDocument() { |
114 // This is hard to test, but we can at least verify we can access ourselves. | 115 // This is hard to test, but we can at least verify we can access ourselves. |
115 ASSERT_TRUE(util_->DocumentCanAccessDocument(*instance_, *instance_)); | 116 ASSERT_TRUE(util_->DocumentCanAccessDocument(*instance_, *instance_)); |
116 PASS(); | 117 PASS(); |
117 } | 118 } |
| 119 |
| 120 std::string TestURLUtil::TestGetDocumentURL() { |
| 121 pp::Var url = util_->GetDocumentURL(*instance_); |
| 122 ASSERT_TRUE(url.is_string()); |
| 123 pp::Var window = instance_->GetWindowObject(); |
| 124 pp::Var href = window.GetProperty("location").GetProperty("href"); |
| 125 ASSERT_TRUE(href.is_string()); |
| 126 // In the test framework, they should be the same. |
| 127 ASSERT_EQ(url.AsString(), href.AsString()); |
| 128 PASS(); |
| 129 } |
OLD | NEW |