gdata_wapi_url_generator_unittest.cc revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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 3// found in the LICENSE file. 4 5#include "google_apis/drive/gdata_wapi_url_generator.h" 6 7#include "testing/gtest/include/gtest/gtest.h" 8#include "url/gurl.h" 9#include "url/url_util.h" 10 11namespace google_apis { 12 13class GDataWapiUrlGeneratorTest : public testing::Test { 14 public: 15 GDataWapiUrlGeneratorTest() 16 : url_generator_( 17 GURL(GDataWapiUrlGenerator::kBaseUrlForProduction), 18 GURL(GDataWapiUrlGenerator::kBaseDownloadUrlForProduction)) { 19 } 20 21 protected: 22 GDataWapiUrlGenerator url_generator_; 23}; 24 25TEST_F(GDataWapiUrlGeneratorTest, AddStandardUrlParams) { 26 EXPECT_EQ("http://www.example.com/?v=3&alt=json&showroot=true", 27 GDataWapiUrlGenerator::AddStandardUrlParams( 28 GURL("http://www.example.com")).spec()); 29} 30 31TEST_F(GDataWapiUrlGeneratorTest, AddInitiateUploadUrlParams) { 32 EXPECT_EQ("http://www.example.com/?convert=false&v=3&alt=json&showroot=true", 33 GDataWapiUrlGenerator::AddInitiateUploadUrlParams( 34 GURL("http://www.example.com")).spec()); 35} 36 37TEST_F(GDataWapiUrlGeneratorTest, AddFeedUrlParams) { 38 EXPECT_EQ( 39 "http://www.example.com/?v=3&alt=json&showroot=true&" 40 "showfolders=true" 41 "&include-shared=true" 42 "&max-results=100", 43 GDataWapiUrlGenerator::AddFeedUrlParams(GURL("http://www.example.com"), 44 100 // num_items_to_fetch 45 ).spec()); 46} 47 48TEST_F(GDataWapiUrlGeneratorTest, GenerateResourceListUrl) { 49 // This is the very basic URL for the GetResourceList request. 50 EXPECT_EQ("https://docs.google.com/feeds/default/private/full" 51 "?v=3&alt=json&showroot=true&showfolders=true&include-shared=true" 52 "&max-results=500", 53 url_generator_.GenerateResourceListUrl( 54 GURL(), // override_url, 55 0, // start_changestamp, 56 std::string(), // search_string, 57 std::string() // directory resource ID 58 ).spec()); 59 60 // With an override URL provided, the base URL is changed, but the default 61 // parameters remain as-is. 62 EXPECT_EQ("http://localhost/" 63 "?v=3&alt=json&showroot=true&showfolders=true&include-shared=true" 64 "&max-results=500", 65 url_generator_.GenerateResourceListUrl( 66 GURL("http://localhost/"), // override_url, 67 0, // start_changestamp, 68 std::string(), // search_string, 69 std::string() // directory resource ID 70 ).spec()); 71 72 // With a non-zero start_changestamp provided, the base URL is changed from 73 // "full" to "changes", and "start-index" parameter is added. 74 EXPECT_EQ("https://docs.google.com/feeds/default/private/changes" 75 "?v=3&alt=json&showroot=true&showfolders=true&include-shared=true" 76 "&max-results=500&start-index=100", 77 url_generator_.GenerateResourceListUrl( 78 GURL(), // override_url, 79 100, // start_changestamp, 80 std::string(), // search_string, 81 std::string() // directory resource ID 82 ).spec()); 83 84 // With a non-empty search string provided, "max-results" value is changed, 85 // and "q" parameter is added. 86 EXPECT_EQ("https://docs.google.com/feeds/default/private/full" 87 "?v=3&alt=json&showroot=true&showfolders=true&include-shared=true" 88 "&max-results=50&q=foo", 89 url_generator_.GenerateResourceListUrl( 90 GURL(), // override_url, 91 0, // start_changestamp, 92 "foo", // search_string, 93 std::string() // directory resource ID 94 ).spec()); 95 96 // With a non-empty directory resource ID provided, the base URL is 97 // changed, but the default parameters remain. 98 EXPECT_EQ( 99 "https://docs.google.com/feeds/default/private/full/XXX/contents" 100 "?v=3&alt=json&showroot=true&showfolders=true&include-shared=true" 101 "&max-results=500", 102 url_generator_.GenerateResourceListUrl(GURL(), // override_url, 103 0, // start_changestamp, 104 std::string(), // search_string, 105 "XXX" // directory resource ID 106 ).spec()); 107 108 // With a non-empty override_url provided, the base URL is changed, but 109 // the default parameters remain. Note that start-index should not be 110 // overridden. 111 EXPECT_EQ("http://example.com/" 112 "?start-index=123&v=3&alt=json&showroot=true&showfolders=true" 113 "&include-shared=true&max-results=500", 114 url_generator_.GenerateResourceListUrl( 115 GURL("http://example.com/?start-index=123"), // override_url, 116 100, // start_changestamp, 117 std::string(), // search_string, 118 "XXX" // directory resource ID 119 ).spec()); 120} 121 122TEST_F(GDataWapiUrlGeneratorTest, GenerateSearchByTitleUrl) { 123 EXPECT_EQ( 124 "https://docs.google.com/feeds/default/private/full" 125 "?v=3&alt=json&showroot=true&showfolders=true&include-shared=true" 126 "&max-results=500&title=search-title&title-exact=true", 127 url_generator_.GenerateSearchByTitleUrl( 128 "search-title", std::string()).spec()); 129 130 EXPECT_EQ( 131 "https://docs.google.com/feeds/default/private/full/XXX/contents" 132 "?v=3&alt=json&showroot=true&showfolders=true&include-shared=true" 133 "&max-results=500&title=search-title&title-exact=true", 134 url_generator_.GenerateSearchByTitleUrl( 135 "search-title", "XXX").spec()); 136} 137 138TEST_F(GDataWapiUrlGeneratorTest, GenerateEditUrl) { 139 EXPECT_EQ( 140 "https://docs.google.com/feeds/default/private/full/XXX?v=3&alt=json" 141 "&showroot=true", 142 url_generator_.GenerateEditUrl("XXX").spec()); 143} 144 145TEST_F(GDataWapiUrlGeneratorTest, GenerateEditUrlWithoutParams) { 146 EXPECT_EQ( 147 "https://docs.google.com/feeds/default/private/full/XXX", 148 url_generator_.GenerateEditUrlWithoutParams("XXX").spec()); 149} 150 151TEST_F(GDataWapiUrlGeneratorTest, GenerateEditUrlWithEmbedOrigin) { 152 url_util::AddStandardScheme("chrome-extension"); 153 154 EXPECT_EQ( 155 "https://docs.google.com/feeds/default/private/full/XXX?v=3&alt=json" 156 "&showroot=true&embedOrigin=chrome-extension%3A%2F%2Ftest", 157 url_generator_.GenerateEditUrlWithEmbedOrigin( 158 "XXX", 159 GURL("chrome-extension://test")).spec()); 160 EXPECT_EQ( 161 "https://docs.google.com/feeds/default/private/full/XXX?v=3&alt=json" 162 "&showroot=true", 163 url_generator_.GenerateEditUrlWithEmbedOrigin( 164 "XXX", 165 GURL()).spec()); 166} 167 168TEST_F(GDataWapiUrlGeneratorTest, GenerateContentUrl) { 169 EXPECT_EQ( 170 "https://docs.google.com/feeds/default/private/full/" 171 "folder%3Aroot/contents?v=3&alt=json&showroot=true", 172 url_generator_.GenerateContentUrl("folder:root").spec()); 173} 174 175TEST_F(GDataWapiUrlGeneratorTest, GenerateResourceUrlForRemoval) { 176 EXPECT_EQ( 177 "https://docs.google.com/feeds/default/private/full/" 178 "folder%3Aroot/contents/file%3AABCDE?v=3&alt=json&showroot=true", 179 url_generator_.GenerateResourceUrlForRemoval( 180 "folder:root", "file:ABCDE").spec()); 181} 182 183TEST_F(GDataWapiUrlGeneratorTest, GenerateInitiateUploadNewFileUrl) { 184 EXPECT_EQ( 185 "https://docs.google.com/feeds/upload/create-session/default/private/" 186 "full/folder%3Aabcde/contents?convert=false&v=3&alt=json&showroot=true", 187 url_generator_.GenerateInitiateUploadNewFileUrl("folder:abcde").spec()); 188} 189 190TEST_F(GDataWapiUrlGeneratorTest, GenerateInitiateUploadExistingFileUrl) { 191 EXPECT_EQ( 192 "https://docs.google.com/feeds/upload/create-session/default/private/" 193 "full/file%3Aresource_id?convert=false&v=3&alt=json&showroot=true", 194 url_generator_.GenerateInitiateUploadExistingFileUrl( 195 "file:resource_id").spec()); 196} 197 198TEST_F(GDataWapiUrlGeneratorTest, GenerateResourceListRootUrl) { 199 EXPECT_EQ( 200 "https://docs.google.com/feeds/default/private/full?v=3&alt=json" 201 "&showroot=true", 202 url_generator_.GenerateResourceListRootUrl().spec()); 203} 204 205TEST_F(GDataWapiUrlGeneratorTest, GenerateAccountMetadataUrl) { 206 // Include installed apps. 207 EXPECT_EQ( 208 "https://docs.google.com/feeds/metadata/default" 209 "?v=3&alt=json&showroot=true&include-installed-apps=true", 210 url_generator_.GenerateAccountMetadataUrl(true).spec()); 211 212 // Exclude installed apps. 213 EXPECT_EQ( 214 "https://docs.google.com/feeds/metadata/default?v=3&alt=json" 215 "&showroot=true", 216 url_generator_.GenerateAccountMetadataUrl(false).spec()); 217} 218 219TEST_F(GDataWapiUrlGeneratorTest, GenerateDownloadFileUrl) { 220 EXPECT_EQ( 221 "https://www.googledrive.com/host/resourceId", 222 url_generator_.GenerateDownloadFileUrl("file:resourceId").spec()); 223} 224 225} // namespace google_apis 226