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