summaryrefslogtreecommitdiffstats
path: root/chrome/browser/google_apis/gdata_wapi_url_generator_unittest.cc
blob: de806990457a328c1de0f8ececc5ba530c646cbf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/google_apis/gdata_wapi_url_generator.h"

#include "googleurl/src/gurl.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace google_apis {

class GDataWapiUrlGeneratorTest : public testing::Test {
 public:
  GDataWapiUrlGeneratorTest()
      : url_generator_(GURL(GDataWapiUrlGenerator::kBaseUrlForProduction)) {
  }

 protected:
  GDataWapiUrlGenerator url_generator_;
};

TEST_F(GDataWapiUrlGeneratorTest, AddStandardUrlParams) {
  EXPECT_EQ("http://www.example.com/?v=3&alt=json&showroot=true",
            GDataWapiUrlGenerator::AddStandardUrlParams(
                GURL("http://www.example.com")).spec());
}

TEST_F(GDataWapiUrlGeneratorTest, AddInitiateUploadUrlParams) {
  EXPECT_EQ("http://www.example.com/?convert=false&v=3&alt=json&showroot=true",
            GDataWapiUrlGenerator::AddInitiateUploadUrlParams(
                GURL("http://www.example.com")).spec());
}

TEST_F(GDataWapiUrlGeneratorTest, AddFeedUrlParams) {
  EXPECT_EQ(
      "http://www.example.com/?v=3&alt=json&showroot=true&"
      "showfolders=true"
      "&include-shared=true"
      "&max-results=100"
      "&include-installed-apps=true",
      GDataWapiUrlGenerator::AddFeedUrlParams(GURL("http://www.example.com"),
                                              100,  // num_items_to_fetch
                                              0,    // changestamp
                                              std::string()  // search_string
                                              ).spec());
  EXPECT_EQ(
      "http://www.example.com/?v=3&alt=json&showroot=true&"
      "showfolders=true"
      "&include-shared=true"
      "&max-results=100"
      "&include-installed-apps=true"
      "&start-index=123",
      GDataWapiUrlGenerator::AddFeedUrlParams(GURL("http://www.example.com"),
                                              100,  // num_items_to_fetch
                                              123,  // changestamp
                                              std::string()  // search_string
                                              ).spec());
  EXPECT_EQ("http://www.example.com/?v=3&alt=json&showroot=true&"
            "showfolders=true"
            "&include-shared=true"
            "&max-results=100"
            "&include-installed-apps=true"
            "&start-index=123"
            "&q=%22foo+bar%22",
            GDataWapiUrlGenerator::AddFeedUrlParams(
                GURL("http://www.example.com"),
                100,  // num_items_to_fetch
                123,  // changestamp
                "\"foo bar\""  // search_string
                                                 ).spec());
}

TEST_F(GDataWapiUrlGeneratorTest, GenerateResourceListUrl) {
  // This is the very basic URL for the GetResourceList operation.
  EXPECT_EQ("https://docs.google.com/feeds/default/private/full"
            "?v=3&alt=json&showroot=true&showfolders=true&include-shared=true"
            "&max-results=500&include-installed-apps=true",
            url_generator_.GenerateResourceListUrl(
                GURL(),         // override_url,
                0,              // start_changestamp,
                std::string(),  // search_string,
                std::string()   // directory resource ID
                ).spec());

  // With an override URL provided, the base URL is changed, but the default
  // parameters remain as-is.
  EXPECT_EQ("http://localhost/"
            "?v=3&alt=json&showroot=true&showfolders=true&include-shared=true"
            "&max-results=500&include-installed-apps=true",
            url_generator_.GenerateResourceListUrl(
                GURL("http://localhost/"),  // override_url,
                0,                          // start_changestamp,
                std::string(),              // search_string,
                std::string()               // directory resource ID
                ).spec());

  // With a non-zero start_changestamp provided, the base URL is changed from
  // "full" to "changes", and "start-index" parameter is added.
  EXPECT_EQ("https://docs.google.com/feeds/default/private/changes"
            "?v=3&alt=json&showroot=true&showfolders=true&include-shared=true"
            "&max-results=500&include-installed-apps=true"
            "&start-index=100",
            url_generator_.GenerateResourceListUrl(
                GURL(),         // override_url,
                100,            // start_changestamp,
                std::string(),  // search_string,
                std::string()   // directory resource ID
                ).spec());

  // With a non-empty search string provided, "max-results" value is changed,
  // and "q" parameter is added.
  EXPECT_EQ("https://docs.google.com/feeds/default/private/full"
            "?v=3&alt=json&showroot=true&showfolders=true&include-shared=true"
            "&max-results=50&include-installed-apps=true&q=foo",
            url_generator_.GenerateResourceListUrl(
                GURL(),        // override_url,
                0,             // start_changestamp,
                "foo",         // search_string,
                std::string()  // directory resource ID
                ).spec());

  // With a non-empty directory resource ID provided, the base URL is
  // changed, but the default parameters remain.
  EXPECT_EQ(
      "https://docs.google.com/feeds/default/private/full/XXX/contents"
      "?v=3&alt=json&showroot=true&showfolders=true&include-shared=true"
      "&max-results=500&include-installed-apps=true",
      url_generator_.GenerateResourceListUrl(GURL(),  // override_url,
                                             0,       // start_changestamp,
                                             std::string(),  // search_string,
                                             "XXX"  // directory resource ID
                                             ).spec());

  // With a non-empty override_url provided, the base URL is changed, but
  // the default parameters remain. Note that start-index should not be
  // overridden.
  EXPECT_EQ("http://example.com/"
            "?start-index=123&v=3&alt=json&showroot=true&showfolders=true"
            "&include-shared=true&max-results=500&include-installed-apps=true",
            url_generator_.GenerateResourceListUrl(
                GURL("http://example.com/?start-index=123"),  // override_url,
                100,            // start_changestamp,
                std::string(),  // search_string,
                "XXX"           // directory resource ID
                ).spec());
}

TEST_F(GDataWapiUrlGeneratorTest, GenerateEditUrl) {
  EXPECT_EQ(
      "https://docs.google.com/feeds/default/private/full/XXX?v=3&alt=json"
      "&showroot=true",
      url_generator_.GenerateEditUrl("XXX").spec());
}

TEST_F(GDataWapiUrlGeneratorTest, GenerateEditUrlWithoutParams) {
  EXPECT_EQ(
      "https://docs.google.com/feeds/default/private/full/XXX",
      url_generator_.GenerateEditUrlWithoutParams("XXX").spec());
}

TEST_F(GDataWapiUrlGeneratorTest, GenerateContentUrl) {
  EXPECT_EQ(
      "https://docs.google.com/feeds/default/private/full/"
      "folder%3Aroot/contents?v=3&alt=json&showroot=true",
      url_generator_.GenerateContentUrl("folder:root").spec());
}

TEST_F(GDataWapiUrlGeneratorTest, GenerateResourceUrlForRemoval) {
  EXPECT_EQ(
      "https://docs.google.com/feeds/default/private/full/"
      "folder%3Aroot/contents/file%3AABCDE?v=3&alt=json&showroot=true",
      url_generator_.GenerateResourceUrlForRemoval(
          "folder:root", "file:ABCDE").spec());
}

TEST_F(GDataWapiUrlGeneratorTest, GenerateInitiateUploadNewFileUrl) {
  EXPECT_EQ(
      "https://docs.google.com/feeds/upload/create-session/default/private/"
      "full/folder%3Aabcde/contents?convert=false&v=3&alt=json&showroot=true",
      url_generator_.GenerateInitiateUploadNewFileUrl("folder:abcde").spec());
}

TEST_F(GDataWapiUrlGeneratorTest, GenerateInitiateUploadExistingFileUrl) {
  EXPECT_EQ(
      "https://docs.google.com/feeds/upload/create-session/default/private/"
      "full/file%3Aresource_id?convert=false&v=3&alt=json&showroot=true",
      url_generator_.GenerateInitiateUploadExistingFileUrl(
          "file:resource_id").spec());
}

TEST_F(GDataWapiUrlGeneratorTest, GenerateResourceListRootUrl) {
  EXPECT_EQ(
      "https://docs.google.com/feeds/default/private/full?v=3&alt=json"
      "&showroot=true",
      url_generator_.GenerateResourceListRootUrl().spec());
}

TEST_F(GDataWapiUrlGeneratorTest, GenerateAccountMetadataUrl) {
  // Include installed apps.
  EXPECT_EQ(
      "https://docs.google.com/feeds/metadata/default"
      "?v=3&alt=json&showroot=true&include-installed-apps=true",
      url_generator_.GenerateAccountMetadataUrl(true).spec());

  // Exclude installed apps.
  EXPECT_EQ(
      "https://docs.google.com/feeds/metadata/default?v=3&alt=json"
      "&showroot=true",
      url_generator_.GenerateAccountMetadataUrl(false).spec());
}

}  // namespace google_apis