OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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/apps/drive/drive_app_mapping.h" |
| 6 |
| 7 #include "base/macros.h" |
| 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "chrome/test/base/testing_pref_service_syncable.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 |
| 12 class DriveAppMappingTest : public testing::Test { |
| 13 public: |
| 14 DriveAppMappingTest() {} |
| 15 virtual ~DriveAppMappingTest() {} |
| 16 |
| 17 // testing::Test: |
| 18 virtual void SetUp() OVERRIDE { |
| 19 pref_service_.reset(new TestingPrefServiceSyncable); |
| 20 DriveAppMapping::RegisterProfilePrefs(pref_service_->registry()); |
| 21 |
| 22 mapping_.reset(new DriveAppMapping(pref_service_.get())); |
| 23 } |
| 24 |
| 25 DriveAppMapping* mapping() { return mapping_.get(); } |
| 26 |
| 27 private: |
| 28 scoped_ptr<TestingPrefServiceSyncable> pref_service_; |
| 29 scoped_ptr<DriveAppMapping> mapping_; |
| 30 |
| 31 DISALLOW_COPY_AND_ASSIGN(DriveAppMappingTest); |
| 32 }; |
| 33 |
| 34 TEST_F(DriveAppMappingTest, Empty) { |
| 35 EXPECT_EQ("", mapping()->GetChromeApp("")); |
| 36 EXPECT_EQ("", mapping()->GetDriveApp("")); |
| 37 EXPECT_EQ("", mapping()->GetChromeApp("non-existent-drive-app")); |
| 38 EXPECT_EQ("", mapping()->GetDriveApp("non-existent-chrome-app")); |
| 39 EXPECT_EQ(0u, mapping()->GetDriveAppIds().size()); |
| 40 } |
| 41 |
| 42 TEST_F(DriveAppMappingTest, Add) { |
| 43 std::set<std::string> drive_app_ids; |
| 44 |
| 45 // Add one. |
| 46 mapping()->Add("drive", "chrome"); |
| 47 EXPECT_EQ("chrome", mapping()->GetChromeApp("drive")); |
| 48 EXPECT_EQ("drive", mapping()->GetDriveApp("chrome")); |
| 49 drive_app_ids = mapping()->GetDriveAppIds(); |
| 50 EXPECT_EQ(1u, drive_app_ids.size()); |
| 51 EXPECT_EQ(1u, drive_app_ids.count("drive")); |
| 52 |
| 53 // Overwrite previous mapping if added under the same key. |
| 54 mapping()->Add("drive", "another-chrome-app"); |
| 55 EXPECT_EQ("", mapping()->GetDriveApp("chrome")); |
| 56 EXPECT_EQ("another-chrome-app", mapping()->GetChromeApp("drive")); |
| 57 EXPECT_EQ("drive", mapping()->GetDriveApp("another-chrome-app")); |
| 58 drive_app_ids = mapping()->GetDriveAppIds(); |
| 59 EXPECT_EQ(1u, drive_app_ids.size()); |
| 60 EXPECT_EQ(1u, drive_app_ids.count("drive")); |
| 61 |
| 62 // Add another one. |
| 63 mapping()->Add("drive-1", "chrome-1"); |
| 64 EXPECT_EQ("chrome-1", mapping()->GetChromeApp("drive-1")); |
| 65 EXPECT_EQ("drive-1", mapping()->GetDriveApp("chrome-1")); |
| 66 drive_app_ids = mapping()->GetDriveAppIds(); |
| 67 EXPECT_EQ(2u, drive_app_ids.size()); |
| 68 EXPECT_EQ(1u, drive_app_ids.count("drive")); |
| 69 EXPECT_EQ(1u, drive_app_ids.count("drive-1")); |
| 70 |
| 71 // Previous mapping should not be affected by new mapping. |
| 72 EXPECT_EQ("another-chrome-app", mapping()->GetChromeApp("drive")); |
| 73 EXPECT_EQ("drive", mapping()->GetDriveApp("another-chrome-app")); |
| 74 |
| 75 // Non-existent value returns empty string. |
| 76 EXPECT_EQ("", mapping()->GetChromeApp("non-existent-drive-app")); |
| 77 EXPECT_EQ("", mapping()->GetDriveApp("non-existent-chrome-app")); |
| 78 } |
| 79 |
| 80 TEST_F(DriveAppMappingTest, Remove) { |
| 81 std::set<std::string> drive_app_ids; |
| 82 |
| 83 // Prepare data. |
| 84 mapping()->Add("drive-1", "chrome-1"); |
| 85 mapping()->Add("drive-2", "chrome-2"); |
| 86 drive_app_ids = mapping()->GetDriveAppIds(); |
| 87 EXPECT_EQ(2u, drive_app_ids.size()); |
| 88 |
| 89 // Remove non-existent. |
| 90 mapping()->Remove("non-existent-drive-app"); |
| 91 drive_app_ids = mapping()->GetDriveAppIds(); |
| 92 EXPECT_EQ(2u, drive_app_ids.size()); |
| 93 |
| 94 // Remove one. |
| 95 EXPECT_EQ("chrome-1", mapping()->GetChromeApp("drive-1")); |
| 96 mapping()->Remove("drive-1"); |
| 97 EXPECT_EQ("", mapping()->GetChromeApp("drive-1")); |
| 98 drive_app_ids = mapping()->GetDriveAppIds(); |
| 99 EXPECT_EQ(1u, drive_app_ids.size()); |
| 100 |
| 101 // Remove it again has no effect. |
| 102 mapping()->Remove("drive-1"); |
| 103 drive_app_ids = mapping()->GetDriveAppIds(); |
| 104 EXPECT_EQ(1u, drive_app_ids.size()); |
| 105 |
| 106 // Remove another one. |
| 107 EXPECT_EQ("chrome-2", mapping()->GetChromeApp("drive-2")); |
| 108 mapping()->Remove("drive-2"); |
| 109 EXPECT_EQ("", mapping()->GetChromeApp("drive-2")); |
| 110 drive_app_ids = mapping()->GetDriveAppIds(); |
| 111 EXPECT_EQ(0u, drive_app_ids.size()); |
| 112 } |
OLD | NEW |