| OLD | NEW |
| (Empty) |
| 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 "chrome/browser/google_apis/gdata_wapi_url_util.h" | |
| 6 | |
| 7 #include "googleurl/src/gurl.h" | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | |
| 9 | |
| 10 namespace google_apis { | |
| 11 namespace gdata_wapi_url_util { | |
| 12 | |
| 13 TEST(GDataWapiUrlUtilTest, AddStandardUrlParams) { | |
| 14 EXPECT_EQ("http://www.example.com/?v=3&alt=json", | |
| 15 AddStandardUrlParams(GURL("http://www.example.com")).spec()); | |
| 16 } | |
| 17 | |
| 18 TEST(GDataWapiUrlUtilTest, AddMetadataUrlParams) { | |
| 19 EXPECT_EQ("http://www.example.com/?v=3&alt=json&include-installed-apps=true", | |
| 20 AddMetadataUrlParams(GURL("http://www.example.com")).spec()); | |
| 21 } | |
| 22 | |
| 23 TEST(GDataWapiUrlUtilTest, AddFeedUrlParams) { | |
| 24 EXPECT_EQ("http://www.example.com/?v=3&alt=json&showfolders=true" | |
| 25 "&max-results=100" | |
| 26 "&include-installed-apps=true", | |
| 27 AddFeedUrlParams(GURL("http://www.example.com"), | |
| 28 100, // num_items_to_fetch | |
| 29 0, // changestamp | |
| 30 "" // search_string | |
| 31 ).spec()); | |
| 32 EXPECT_EQ("http://www.example.com/?v=3&alt=json&showfolders=true" | |
| 33 "&max-results=100" | |
| 34 "&include-installed-apps=true" | |
| 35 "&start-index=123", | |
| 36 AddFeedUrlParams(GURL("http://www.example.com"), | |
| 37 100, // num_items_to_fetch | |
| 38 123, // changestamp | |
| 39 "" // search_string | |
| 40 ).spec()); | |
| 41 EXPECT_EQ("http://www.example.com/?v=3&alt=json&showfolders=true" | |
| 42 "&max-results=100" | |
| 43 "&include-installed-apps=true" | |
| 44 "&start-index=123" | |
| 45 "&q=%22foo+bar%22", | |
| 46 AddFeedUrlParams(GURL("http://www.example.com"), | |
| 47 100, // num_items_to_fetch | |
| 48 123, // changestamp | |
| 49 "\"foo bar\"" // search_string | |
| 50 ).spec()); | |
| 51 } | |
| 52 | |
| 53 } // namespace gdata_wapi_url_util | |
| 54 | |
| 55 // TODO(satorux): Move the following test code to a separate file | |
| 56 // gdata_wapi_url_generator_unittest.cc. | |
| 57 class GDataWapiUrlGeneratorTest : public testing::Test { | |
| 58 public: | |
| 59 GDataWapiUrlGeneratorTest() | |
| 60 : url_generator_(GURL(gdata_wapi_url_util::kBaseUrlForProduction)) { | |
| 61 } | |
| 62 | |
| 63 protected: | |
| 64 GDataWapiUrlGenerator url_generator_; | |
| 65 }; | |
| 66 | |
| 67 TEST_F(GDataWapiUrlGeneratorTest, GenerateDocumentListUrl) { | |
| 68 // This is the very basic URL for the GetDocuments operation. | |
| 69 EXPECT_EQ( | |
| 70 "https://docs.google.com/feeds/default/private/full/-/mine" | |
| 71 "?v=3&alt=json&showfolders=true&max-results=500" | |
| 72 "&include-installed-apps=true", | |
| 73 url_generator_.GenerateDocumentListUrl(GURL(), // override_url, | |
| 74 0, // start_changestamp, | |
| 75 "", // search_string, | |
| 76 false, // shared_with_me, | |
| 77 "" // directory resource ID | |
| 78 ).spec()); | |
| 79 | |
| 80 // With an override URL provided, the base URL is changed, but the default | |
| 81 // parameters remain as-is. | |
| 82 EXPECT_EQ( | |
| 83 "http://localhost/" | |
| 84 "?v=3&alt=json&showfolders=true&max-results=500" | |
| 85 "&include-installed-apps=true", | |
| 86 url_generator_.GenerateDocumentListUrl( | |
| 87 GURL("http://localhost/"), // override_url, | |
| 88 0, // start_changestamp, | |
| 89 "", // search_string, | |
| 90 false, // shared_with_me, | |
| 91 "" // directory resource ID | |
| 92 ).spec()); | |
| 93 | |
| 94 // With a non-zero start_changestamp provided, the base URL is changed from | |
| 95 // "full/-/mine" to "changes", and "start-index" parameter is added. | |
| 96 EXPECT_EQ( | |
| 97 "https://docs.google.com/feeds/default/private/changes" | |
| 98 "?v=3&alt=json&showfolders=true&max-results=500" | |
| 99 "&include-installed-apps=true" | |
| 100 "&start-index=100", | |
| 101 url_generator_.GenerateDocumentListUrl(GURL(), // override_url, | |
| 102 100, // start_changestamp, | |
| 103 "", // search_string, | |
| 104 false, // shared_with_me, | |
| 105 "" // directory resource ID | |
| 106 ).spec()); | |
| 107 | |
| 108 // With a non-empty search string provided, "max-results" value is changed, | |
| 109 // and "q" parameter is added. | |
| 110 EXPECT_EQ( | |
| 111 "https://docs.google.com/feeds/default/private/full/-/mine" | |
| 112 "?v=3&alt=json&showfolders=true&max-results=50" | |
| 113 "&include-installed-apps=true&q=foo", | |
| 114 url_generator_.GenerateDocumentListUrl(GURL(), // override_url, | |
| 115 0, // start_changestamp, | |
| 116 "foo", // search_string, | |
| 117 false, // shared_with_me, | |
| 118 "" // directory resource ID | |
| 119 ).spec()); | |
| 120 | |
| 121 // With shared_with_me parameter set to true, the base URL is changed, but | |
| 122 // the default parameters remain. | |
| 123 EXPECT_EQ( | |
| 124 "https://docs.google.com/feeds/default/private/full/-/shared-with-me" | |
| 125 "?v=3&alt=json&showfolders=true&max-results=500" | |
| 126 "&include-installed-apps=true", | |
| 127 url_generator_.GenerateDocumentListUrl(GURL(), // override_url, | |
| 128 0, // start_changestamp, | |
| 129 "", // search_string, | |
| 130 true, // shared_with_me, | |
| 131 "" // directory resource ID | |
| 132 ).spec()); | |
| 133 | |
| 134 // With a non-empty directory resource ID provided, the base URL is | |
| 135 // changed, but the default parameters remain. | |
| 136 EXPECT_EQ( | |
| 137 "https://docs.google.com/feeds/default/private/full/XXX/contents/-/mine" | |
| 138 "?v=3&alt=json&showfolders=true&max-results=500" | |
| 139 "&include-installed-apps=true", | |
| 140 url_generator_.GenerateDocumentListUrl(GURL(), // override_url, | |
| 141 0, // start_changestamp, | |
| 142 "", // search_string, | |
| 143 false, // shared_with_me, | |
| 144 "XXX" // directory resource ID | |
| 145 ).spec()); | |
| 146 } | |
| 147 | |
| 148 TEST_F(GDataWapiUrlGeneratorTest, GenerateDocumentEntryUrl) { | |
| 149 EXPECT_EQ( | |
| 150 "https://docs.google.com/feeds/default/private/full/XXX?v=3&alt=json", | |
| 151 url_generator_.GenerateDocumentEntryUrl("XXX").spec()); | |
| 152 } | |
| 153 | |
| 154 TEST_F(GDataWapiUrlGeneratorTest, GenerateDocumentListRootUrl) { | |
| 155 EXPECT_EQ( | |
| 156 "https://docs.google.com/feeds/default/private/full?v=3&alt=json", | |
| 157 url_generator_.GenerateDocumentListRootUrl().spec()); | |
| 158 } | |
| 159 | |
| 160 TEST_F(GDataWapiUrlGeneratorTest, GenerateAccountMetadataUrl) { | |
| 161 EXPECT_EQ( | |
| 162 "https://docs.google.com/feeds/metadata/default" | |
| 163 "?v=3&alt=json&include-installed-apps=true", | |
| 164 url_generator_.GenerateAccountMetadataUrl().spec()); | |
| 165 } | |
| 166 | |
| 167 } // namespace google_apis | |
| OLD | NEW |