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