OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/drive_api_url_generator.h" | 5 #include "chrome/browser/google_apis/drive_api_url_generator.h" |
6 | 6 |
| 7 #include "chrome/browser/google_apis/test_util.h" |
7 #include "googleurl/src/gurl.h" | 8 #include "googleurl/src/gurl.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
9 | 10 |
10 namespace google_apis { | 11 namespace google_apis { |
11 | 12 |
12 class DriveApiUrlGeneratorTest : public testing::Test { | 13 class DriveApiUrlGeneratorTest : public testing::Test { |
13 public: | 14 public: |
14 DriveApiUrlGeneratorTest() { | 15 DriveApiUrlGeneratorTest() |
| 16 : url_generator_(GURL(DriveApiUrlGenerator::kBaseUrlForProduction)), |
| 17 test_url_generator_(test_util::GetBaseUrlForTesting(12345)) { |
15 } | 18 } |
16 | 19 |
17 protected: | 20 protected: |
18 DriveApiUrlGenerator url_generator_; | 21 DriveApiUrlGenerator url_generator_; |
| 22 DriveApiUrlGenerator test_url_generator_; |
19 }; | 23 }; |
20 | 24 |
21 // Make sure the hard-coded urls are returned. | 25 // Make sure the hard-coded urls are returned. |
22 // TODO(hidehiko): More detailed tests when we support server path injecting. | |
23 TEST_F(DriveApiUrlGeneratorTest, GetAboutUrl) { | 26 TEST_F(DriveApiUrlGeneratorTest, GetAboutUrl) { |
24 EXPECT_EQ("https://www.googleapis.com/drive/v2/about", | 27 EXPECT_EQ("https://www.googleapis.com/drive/v2/about", |
25 url_generator_.GetAboutUrl().spec()); | 28 url_generator_.GetAboutUrl().spec()); |
| 29 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/about", |
| 30 test_url_generator_.GetAboutUrl().spec()); |
26 } | 31 } |
27 | 32 |
28 TEST_F(DriveApiUrlGeneratorTest, GetApplistUrl) { | 33 TEST_F(DriveApiUrlGeneratorTest, GetApplistUrl) { |
29 EXPECT_EQ("https://www.googleapis.com/drive/v2/apps", | 34 EXPECT_EQ("https://www.googleapis.com/drive/v2/apps", |
30 url_generator_.GetApplistUrl().spec()); | 35 url_generator_.GetApplistUrl().spec()); |
| 36 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/apps", |
| 37 test_url_generator_.GetApplistUrl().spec()); |
31 } | 38 } |
32 | 39 |
33 TEST_F(DriveApiUrlGeneratorTest, GetChangelistUrl) { | 40 TEST_F(DriveApiUrlGeneratorTest, GetChangelistUrl) { |
34 // Use default URL, if |override_url| is empty. | 41 // Use default URL, if |override_url| is empty. |
35 // Do not add startChangeId parameter if |start_changestamp| is 0. | 42 // Do not add startChangeId parameter if |start_changestamp| is 0. |
36 EXPECT_EQ("https://www.googleapis.com/drive/v2/changes", | 43 EXPECT_EQ("https://www.googleapis.com/drive/v2/changes", |
37 url_generator_.GetChangelistUrl(GURL(), 0).spec()); | 44 url_generator_.GetChangelistUrl(GURL(), 0).spec()); |
38 | 45 |
39 // Set startChangeId parameter if |start_changestamp| is given. | 46 // Set startChangeId parameter if |start_changestamp| is given. |
40 EXPECT_EQ("https://www.googleapis.com/drive/v2/changes?startChangeId=100", | 47 EXPECT_EQ("https://www.googleapis.com/drive/v2/changes?startChangeId=100", |
41 url_generator_.GetChangelistUrl(GURL(), 100).spec()); | 48 url_generator_.GetChangelistUrl(GURL(), 100).spec()); |
42 | 49 |
43 // Use the |override_url| for the base URL if given. | 50 // Use the |override_url| for the base URL if given. |
44 // The behavior for the |start_changestamp| should be as same as above cases. | 51 // The behavior for the |start_changestamp| should be as same as above cases. |
45 EXPECT_EQ("https://localhost/drive/v2/changes", | 52 EXPECT_EQ("https://localhost/drive/v2/changes", |
46 url_generator_.GetChangelistUrl( | 53 url_generator_.GetChangelistUrl( |
47 GURL("https://localhost/drive/v2/changes"), 0).spec()); | 54 GURL("https://localhost/drive/v2/changes"), 0).spec()); |
48 EXPECT_EQ("https://localhost/drive/v2/changes?startChangeId=200", | 55 EXPECT_EQ("https://localhost/drive/v2/changes?startChangeId=200", |
49 url_generator_.GetChangelistUrl( | 56 url_generator_.GetChangelistUrl( |
50 GURL("https://localhost/drive/v2/changes"), 200).spec()); | 57 GURL("https://localhost/drive/v2/changes"), 200).spec()); |
| 58 |
| 59 // For test server, the given base url should be used, |
| 60 // but if |override_url| is given, |override_url| should be used. |
| 61 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/changes?startChangeId=100", |
| 62 test_url_generator_.GetChangelistUrl(GURL(), 100).spec()); |
| 63 EXPECT_EQ("https://localhost/drive/v2/changes?startChangeId=200", |
| 64 test_url_generator_.GetChangelistUrl( |
| 65 GURL("https://localhost/drive/v2/changes"), 200).spec()); |
51 } | 66 } |
52 | 67 |
53 TEST_F(DriveApiUrlGeneratorTest, GetFilelistUrl) { | 68 TEST_F(DriveApiUrlGeneratorTest, GetFilelistUrl) { |
54 // Use default URL, if |override_url| is empty. | 69 // Use default URL, if |override_url| is empty. |
55 // Do not add q parameter if |search_string| is empty. | 70 // Do not add q parameter if |search_string| is empty. |
56 EXPECT_EQ("https://www.googleapis.com/drive/v2/files", | 71 EXPECT_EQ("https://www.googleapis.com/drive/v2/files", |
57 url_generator_.GetFilelistUrl(GURL(), "").spec()); | 72 url_generator_.GetFilelistUrl(GURL(), "").spec()); |
58 | 73 |
59 // Set q parameter if non-empty |search_string| is given. | 74 // Set q parameter if non-empty |search_string| is given. |
60 EXPECT_EQ("https://www.googleapis.com/drive/v2/files?q=query", | 75 EXPECT_EQ("https://www.googleapis.com/drive/v2/files?q=query", |
61 url_generator_.GetFilelistUrl(GURL(), "query").spec()); | 76 url_generator_.GetFilelistUrl(GURL(), "query").spec()); |
62 | 77 |
63 // Use the |override_url| for the base URL if given. | 78 // Use the |override_url| for the base URL if given. |
64 // The behavior for the |search_string| should be as same as above cases. | 79 // The behavior for the |search_string| should be as same as above cases. |
65 EXPECT_EQ("https://localhost/drive/v2/files", | 80 EXPECT_EQ("https://localhost/drive/v2/files", |
66 url_generator_.GetFilelistUrl( | 81 url_generator_.GetFilelistUrl( |
67 GURL("https://localhost/drive/v2/files"), "").spec()); | 82 GURL("https://localhost/drive/v2/files"), "").spec()); |
68 EXPECT_EQ("https://localhost/drive/v2/files?q=query", | 83 EXPECT_EQ("https://localhost/drive/v2/files?q=query", |
69 url_generator_.GetFilelistUrl( | 84 url_generator_.GetFilelistUrl( |
70 GURL("https://localhost/drive/v2/files"), "query").spec()); | 85 GURL("https://localhost/drive/v2/files"), "query").spec()); |
| 86 |
| 87 // For test server, the given base url should be used, |
| 88 // but if |override_url| is given, |override_url| should be used. |
| 89 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files?q=query", |
| 90 test_url_generator_.GetFilelistUrl(GURL(), "query").spec()); |
| 91 EXPECT_EQ("https://localhost/drive/v2/files?q=query", |
| 92 test_url_generator_.GetFilelistUrl( |
| 93 GURL("https://localhost/drive/v2/files"), "query").spec()); |
71 } | 94 } |
72 | 95 |
73 TEST_F(DriveApiUrlGeneratorTest, GetFileUrl) { | 96 TEST_F(DriveApiUrlGeneratorTest, GetFileUrl) { |
74 // |file_id| should be embedded into the url. | 97 // |file_id| should be embedded into the url. |
75 EXPECT_EQ("https://www.googleapis.com/drive/v2/files/0ADK06pfg", | 98 EXPECT_EQ("https://www.googleapis.com/drive/v2/files/0ADK06pfg", |
76 url_generator_.GetFileUrl("0ADK06pfg").spec()); | 99 url_generator_.GetFileUrl("0ADK06pfg").spec()); |
77 EXPECT_EQ("https://www.googleapis.com/drive/v2/files/0Bz0bd074", | 100 EXPECT_EQ("https://www.googleapis.com/drive/v2/files/0Bz0bd074", |
78 url_generator_.GetFileUrl("0Bz0bd074").spec()); | 101 url_generator_.GetFileUrl("0Bz0bd074").spec()); |
| 102 |
| 103 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files/0ADK06pfg", |
| 104 test_url_generator_.GetFileUrl("0ADK06pfg").spec()); |
| 105 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files/0Bz0bd074", |
| 106 test_url_generator_.GetFileUrl("0Bz0bd074").spec()); |
79 } | 107 } |
80 | 108 |
81 } // namespace google_apis | 109 } // namespace google_apis |
OLD | NEW |