OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/google_apis/gdata_wapi_url_generator.h" | 5 #include "chrome/browser/google_apis/gdata_wapi_url_generator.h" |
6 | 6 |
7 #include "googleurl/src/gurl.h" | 7 #include "googleurl/src/gurl.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace google_apis { | 10 namespace google_apis { |
(...skipping 18 matching lines...) Expand all Loading... |
29 EXPECT_EQ("http://www.example.com/?convert=false&v=3&alt=json&showroot=true", | 29 EXPECT_EQ("http://www.example.com/?convert=false&v=3&alt=json&showroot=true", |
30 GDataWapiUrlGenerator::AddInitiateUploadUrlParams( | 30 GDataWapiUrlGenerator::AddInitiateUploadUrlParams( |
31 GURL("http://www.example.com")).spec()); | 31 GURL("http://www.example.com")).spec()); |
32 } | 32 } |
33 | 33 |
34 TEST_F(GDataWapiUrlGeneratorTest, AddFeedUrlParams) { | 34 TEST_F(GDataWapiUrlGeneratorTest, AddFeedUrlParams) { |
35 EXPECT_EQ( | 35 EXPECT_EQ( |
36 "http://www.example.com/?v=3&alt=json&showroot=true&" | 36 "http://www.example.com/?v=3&alt=json&showroot=true&" |
37 "showfolders=true" | 37 "showfolders=true" |
38 "&include-shared=true" | 38 "&include-shared=true" |
39 "&max-results=100" | 39 "&max-results=100", |
40 "&include-installed-apps=true", | |
41 GDataWapiUrlGenerator::AddFeedUrlParams(GURL("http://www.example.com"), | 40 GDataWapiUrlGenerator::AddFeedUrlParams(GURL("http://www.example.com"), |
42 100, // num_items_to_fetch | 41 100, // num_items_to_fetch |
43 0, // changestamp | 42 0, // changestamp |
44 std::string() // search_string | 43 std::string() // search_string |
45 ).spec()); | 44 ).spec()); |
46 EXPECT_EQ( | 45 EXPECT_EQ( |
47 "http://www.example.com/?v=3&alt=json&showroot=true&" | 46 "http://www.example.com/?v=3&alt=json&showroot=true&" |
48 "showfolders=true" | 47 "showfolders=true" |
49 "&include-shared=true" | 48 "&include-shared=true" |
50 "&max-results=100" | 49 "&max-results=100" |
51 "&include-installed-apps=true" | |
52 "&start-index=123", | 50 "&start-index=123", |
53 GDataWapiUrlGenerator::AddFeedUrlParams(GURL("http://www.example.com"), | 51 GDataWapiUrlGenerator::AddFeedUrlParams(GURL("http://www.example.com"), |
54 100, // num_items_to_fetch | 52 100, // num_items_to_fetch |
55 123, // changestamp | 53 123, // changestamp |
56 std::string() // search_string | 54 std::string() // search_string |
57 ).spec()); | 55 ).spec()); |
58 EXPECT_EQ("http://www.example.com/?v=3&alt=json&showroot=true&" | 56 EXPECT_EQ("http://www.example.com/?v=3&alt=json&showroot=true&" |
59 "showfolders=true" | 57 "showfolders=true" |
60 "&include-shared=true" | 58 "&include-shared=true" |
61 "&max-results=100" | 59 "&max-results=100" |
62 "&include-installed-apps=true" | |
63 "&start-index=123" | 60 "&start-index=123" |
64 "&q=%22foo+bar%22", | 61 "&q=%22foo+bar%22", |
65 GDataWapiUrlGenerator::AddFeedUrlParams( | 62 GDataWapiUrlGenerator::AddFeedUrlParams( |
66 GURL("http://www.example.com"), | 63 GURL("http://www.example.com"), |
67 100, // num_items_to_fetch | 64 100, // num_items_to_fetch |
68 123, // changestamp | 65 123, // changestamp |
69 "\"foo bar\"" // search_string | 66 "\"foo bar\"" // search_string |
70 ).spec()); | 67 ).spec()); |
71 } | 68 } |
72 | 69 |
73 TEST_F(GDataWapiUrlGeneratorTest, GenerateResourceListUrl) { | 70 TEST_F(GDataWapiUrlGeneratorTest, GenerateResourceListUrl) { |
74 // This is the very basic URL for the GetResourceList operation. | 71 // This is the very basic URL for the GetResourceList operation. |
75 EXPECT_EQ("https://docs.google.com/feeds/default/private/full" | 72 EXPECT_EQ("https://docs.google.com/feeds/default/private/full" |
76 "?v=3&alt=json&showroot=true&showfolders=true&include-shared=true" | 73 "?v=3&alt=json&showroot=true&showfolders=true&include-shared=true" |
77 "&max-results=500&include-installed-apps=true", | 74 "&max-results=500", |
78 url_generator_.GenerateResourceListUrl( | 75 url_generator_.GenerateResourceListUrl( |
79 GURL(), // override_url, | 76 GURL(), // override_url, |
80 0, // start_changestamp, | 77 0, // start_changestamp, |
81 std::string(), // search_string, | 78 std::string(), // search_string, |
82 std::string() // directory resource ID | 79 std::string() // directory resource ID |
83 ).spec()); | 80 ).spec()); |
84 | 81 |
85 // With an override URL provided, the base URL is changed, but the default | 82 // With an override URL provided, the base URL is changed, but the default |
86 // parameters remain as-is. | 83 // parameters remain as-is. |
87 EXPECT_EQ("http://localhost/" | 84 EXPECT_EQ("http://localhost/" |
88 "?v=3&alt=json&showroot=true&showfolders=true&include-shared=true" | 85 "?v=3&alt=json&showroot=true&showfolders=true&include-shared=true" |
89 "&max-results=500&include-installed-apps=true", | 86 "&max-results=500", |
90 url_generator_.GenerateResourceListUrl( | 87 url_generator_.GenerateResourceListUrl( |
91 GURL("http://localhost/"), // override_url, | 88 GURL("http://localhost/"), // override_url, |
92 0, // start_changestamp, | 89 0, // start_changestamp, |
93 std::string(), // search_string, | 90 std::string(), // search_string, |
94 std::string() // directory resource ID | 91 std::string() // directory resource ID |
95 ).spec()); | 92 ).spec()); |
96 | 93 |
97 // With a non-zero start_changestamp provided, the base URL is changed from | 94 // With a non-zero start_changestamp provided, the base URL is changed from |
98 // "full" to "changes", and "start-index" parameter is added. | 95 // "full" to "changes", and "start-index" parameter is added. |
99 EXPECT_EQ("https://docs.google.com/feeds/default/private/changes" | 96 EXPECT_EQ("https://docs.google.com/feeds/default/private/changes" |
100 "?v=3&alt=json&showroot=true&showfolders=true&include-shared=true" | 97 "?v=3&alt=json&showroot=true&showfolders=true&include-shared=true" |
101 "&max-results=500&include-installed-apps=true" | 98 "&max-results=500&start-index=100", |
102 "&start-index=100", | |
103 url_generator_.GenerateResourceListUrl( | 99 url_generator_.GenerateResourceListUrl( |
104 GURL(), // override_url, | 100 GURL(), // override_url, |
105 100, // start_changestamp, | 101 100, // start_changestamp, |
106 std::string(), // search_string, | 102 std::string(), // search_string, |
107 std::string() // directory resource ID | 103 std::string() // directory resource ID |
108 ).spec()); | 104 ).spec()); |
109 | 105 |
110 // With a non-empty search string provided, "max-results" value is changed, | 106 // With a non-empty search string provided, "max-results" value is changed, |
111 // and "q" parameter is added. | 107 // and "q" parameter is added. |
112 EXPECT_EQ("https://docs.google.com/feeds/default/private/full" | 108 EXPECT_EQ("https://docs.google.com/feeds/default/private/full" |
113 "?v=3&alt=json&showroot=true&showfolders=true&include-shared=true" | 109 "?v=3&alt=json&showroot=true&showfolders=true&include-shared=true" |
114 "&max-results=50&include-installed-apps=true&q=foo", | 110 "&max-results=50&q=foo", |
115 url_generator_.GenerateResourceListUrl( | 111 url_generator_.GenerateResourceListUrl( |
116 GURL(), // override_url, | 112 GURL(), // override_url, |
117 0, // start_changestamp, | 113 0, // start_changestamp, |
118 "foo", // search_string, | 114 "foo", // search_string, |
119 std::string() // directory resource ID | 115 std::string() // directory resource ID |
120 ).spec()); | 116 ).spec()); |
121 | 117 |
122 // With a non-empty directory resource ID provided, the base URL is | 118 // With a non-empty directory resource ID provided, the base URL is |
123 // changed, but the default parameters remain. | 119 // changed, but the default parameters remain. |
124 EXPECT_EQ( | 120 EXPECT_EQ( |
125 "https://docs.google.com/feeds/default/private/full/XXX/contents" | 121 "https://docs.google.com/feeds/default/private/full/XXX/contents" |
126 "?v=3&alt=json&showroot=true&showfolders=true&include-shared=true" | 122 "?v=3&alt=json&showroot=true&showfolders=true&include-shared=true" |
127 "&max-results=500&include-installed-apps=true", | 123 "&max-results=500", |
128 url_generator_.GenerateResourceListUrl(GURL(), // override_url, | 124 url_generator_.GenerateResourceListUrl(GURL(), // override_url, |
129 0, // start_changestamp, | 125 0, // start_changestamp, |
130 std::string(), // search_string, | 126 std::string(), // search_string, |
131 "XXX" // directory resource ID | 127 "XXX" // directory resource ID |
132 ).spec()); | 128 ).spec()); |
133 | 129 |
134 // With a non-empty override_url provided, the base URL is changed, but | 130 // With a non-empty override_url provided, the base URL is changed, but |
135 // the default parameters remain. Note that start-index should not be | 131 // the default parameters remain. Note that start-index should not be |
136 // overridden. | 132 // overridden. |
137 EXPECT_EQ("http://example.com/" | 133 EXPECT_EQ("http://example.com/" |
138 "?start-index=123&v=3&alt=json&showroot=true&showfolders=true" | 134 "?start-index=123&v=3&alt=json&showroot=true&showfolders=true" |
139 "&include-shared=true&max-results=500&include-installed-apps=true", | 135 "&include-shared=true&max-results=500", |
140 url_generator_.GenerateResourceListUrl( | 136 url_generator_.GenerateResourceListUrl( |
141 GURL("http://example.com/?start-index=123"), // override_url, | 137 GURL("http://example.com/?start-index=123"), // override_url, |
142 100, // start_changestamp, | 138 100, // start_changestamp, |
143 std::string(), // search_string, | 139 std::string(), // search_string, |
144 "XXX" // directory resource ID | 140 "XXX" // directory resource ID |
145 ).spec()); | 141 ).spec()); |
146 } | 142 } |
147 | 143 |
148 TEST_F(GDataWapiUrlGeneratorTest, GenerateEditUrl) { | 144 TEST_F(GDataWapiUrlGeneratorTest, GenerateEditUrl) { |
149 EXPECT_EQ( | 145 EXPECT_EQ( |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 url_generator_.GenerateAccountMetadataUrl(true).spec()); | 199 url_generator_.GenerateAccountMetadataUrl(true).spec()); |
204 | 200 |
205 // Exclude installed apps. | 201 // Exclude installed apps. |
206 EXPECT_EQ( | 202 EXPECT_EQ( |
207 "https://docs.google.com/feeds/metadata/default?v=3&alt=json" | 203 "https://docs.google.com/feeds/metadata/default?v=3&alt=json" |
208 "&showroot=true", | 204 "&showroot=true", |
209 url_generator_.GenerateAccountMetadataUrl(false).spec()); | 205 url_generator_.GenerateAccountMetadataUrl(false).spec()); |
210 } | 206 } |
211 | 207 |
212 } // namespace google_apis | 208 } // namespace google_apis |
OLD | NEW |