OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/path_service.h" | 5 #include "base/path_service.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #if defined(OS_WIN) | 10 #if defined(OS_WIN) |
11 #include "base/win/windows_version.h" | 11 #include "base/win/windows_version.h" |
(...skipping 20 matching lines...) Expand all Loading... |
32 | 32 |
33 #if defined(OS_WIN) | 33 #if defined(OS_WIN) |
34 // Function to test DIR_LOCAL_APP_DATA_LOW on Windows XP. Make sure it fails. | 34 // Function to test DIR_LOCAL_APP_DATA_LOW on Windows XP. Make sure it fails. |
35 bool ReturnsInvalidPath(int dir_type) { | 35 bool ReturnsInvalidPath(int dir_type) { |
36 FilePath path; | 36 FilePath path; |
37 bool result = PathService::Get(base::DIR_LOCAL_APP_DATA_LOW, &path); | 37 bool result = PathService::Get(base::DIR_LOCAL_APP_DATA_LOW, &path); |
38 return !result && path.empty(); | 38 return !result && path.empty(); |
39 } | 39 } |
40 #endif | 40 #endif |
41 | 41 |
| 42 const int kSimpleProviderKey = 9999; |
| 43 const FilePath::CharType kSimpleProviderPath[] = "."; |
| 44 |
| 45 bool SimpleProvider(int key, FilePath* result) { |
| 46 if (key == kSimpleProviderKey) { |
| 47 *result = FilePath(kSimpleProviderPath); |
| 48 return true; |
| 49 } |
| 50 return false; |
| 51 } |
| 52 |
42 } // namespace | 53 } // namespace |
43 | 54 |
44 // On the Mac this winds up using some autoreleased objects, so we need to | 55 // On the Mac this winds up using some autoreleased objects, so we need to |
45 // be a PlatformTest. | 56 // be a PlatformTest. |
46 typedef PlatformTest PathServiceTest; | 57 typedef PlatformTest PathServiceTest; |
47 | 58 |
48 // Test that all PathService::Get calls return a value and a true result | 59 // Test that all PathService::Get calls return a value and a true result |
49 // in the development environment. (This test was created because a few | 60 // in the development environment. (This test was created because a few |
50 // later changes to Get broke the semantics of the function and yielded the | 61 // later changes to Get broke the semantics of the function and yielded the |
51 // correct value while returning false.) | 62 // correct value while returning false.) |
(...skipping 11 matching lines...) Expand all Loading... |
63 } else { | 74 } else { |
64 EXPECT_TRUE(ReturnsValidPath(key)) << key; | 75 EXPECT_TRUE(ReturnsValidPath(key)) << key; |
65 } | 76 } |
66 } | 77 } |
67 #elif defined(OS_MACOSX) | 78 #elif defined(OS_MACOSX) |
68 for (int key = base::PATH_MAC_START + 1; key < base::PATH_MAC_END; ++key) { | 79 for (int key = base::PATH_MAC_START + 1; key < base::PATH_MAC_END; ++key) { |
69 EXPECT_PRED1(ReturnsValidPath, key); | 80 EXPECT_PRED1(ReturnsValidPath, key); |
70 } | 81 } |
71 #endif | 82 #endif |
72 } | 83 } |
| 84 |
| 85 TEST_F(PathServiceTest, RegisterUnregister) { |
| 86 EXPECT_FALSE(ReturnsValidPath(kSimpleProviderKey)) << kSimpleProviderKey; |
| 87 PathService::RegisterProvider(&SimpleProvider, |
| 88 kSimpleProviderKey, kSimpleProviderKey+1); |
| 89 EXPECT_TRUE(ReturnsValidPath(kSimpleProviderKey)) << kSimpleProviderKey; |
| 90 PathService::UnregisterProvider(&SimpleProvider); |
| 91 EXPECT_FALSE(ReturnsValidPath(kSimpleProviderKey)) << kSimpleProviderKey; |
| 92 } |
OLD | NEW |