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