Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(578)

Side by Side Diff: chrome/browser/apps/drive/drive_app_mapping_unittest.cc

Issue 308003005: app_list: Drive app integration. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: move to c/b/apps, add OWNERS Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 namespace extensions {
13
14 class DriveAppMappingTest : public testing::Test {
15 public:
16 DriveAppMappingTest() {}
17 virtual ~DriveAppMappingTest() {}
18
19 // testing::Test:
20 virtual void SetUp() OVERRIDE {
21 pref_service_.reset(new TestingPrefServiceSyncable);
22 DriveAppMapping::RegisterProfilePrefs(pref_service_->registry());
23
24 mapping_.reset(new DriveAppMapping(pref_service_.get()));
25 }
26
27 DriveAppMapping* mapping() { return mapping_.get(); }
28
29 private:
30 scoped_ptr<TestingPrefServiceSyncable> pref_service_;
31 scoped_ptr<DriveAppMapping> mapping_;
32
33 DISALLOW_COPY_AND_ASSIGN(DriveAppMappingTest);
34 };
35
36 TEST_F(DriveAppMappingTest, Empty) {
37 EXPECT_EQ("", mapping()->GetChromeApp(""));
38 EXPECT_EQ("", mapping()->GetDriveApp(""));
39 EXPECT_EQ("", mapping()->GetChromeApp("non-existent-drive-app"));
40 EXPECT_EQ("", mapping()->GetDriveApp("non-existent-chrome-app"));
41 EXPECT_EQ(0u, mapping()->GetDriveAppIds().size());
42 }
43
44 TEST_F(DriveAppMappingTest, Add) {
45 std::set<std::string> drive_app_ids;
46
47 // Add one.
48 mapping()->Add("drive", "chrome");
49 EXPECT_EQ("chrome", mapping()->GetChromeApp("drive"));
50 EXPECT_EQ("drive", mapping()->GetDriveApp("chrome"));
51 drive_app_ids = mapping()->GetDriveAppIds();
52 EXPECT_EQ(1u, drive_app_ids.size());
53 EXPECT_EQ(1u, drive_app_ids.count("drive"));
54
55 // Overwrite previous mapping if added under the same key.
56 mapping()->Add("drive", "another-chrome-app");
57 EXPECT_EQ("", mapping()->GetDriveApp("chrome"));
58 EXPECT_EQ("another-chrome-app", mapping()->GetChromeApp("drive"));
59 EXPECT_EQ("drive", mapping()->GetDriveApp("another-chrome-app"));
60 drive_app_ids = mapping()->GetDriveAppIds();
61 EXPECT_EQ(1u, drive_app_ids.size());
62 EXPECT_EQ(1u, drive_app_ids.count("drive"));
63
64 // Add another one.
65 mapping()->Add("drive-1", "chrome-1");
66 EXPECT_EQ("chrome-1", mapping()->GetChromeApp("drive-1"));
67 EXPECT_EQ("drive-1", mapping()->GetDriveApp("chrome-1"));
68 drive_app_ids = mapping()->GetDriveAppIds();
69 EXPECT_EQ(2u, drive_app_ids.size());
70 EXPECT_EQ(1u, drive_app_ids.count("drive"));
71 EXPECT_EQ(1u, drive_app_ids.count("drive-1"));
72
73 // Previous mapping should not be affected by new mapping.
74 EXPECT_EQ("another-chrome-app", mapping()->GetChromeApp("drive"));
75 EXPECT_EQ("drive", mapping()->GetDriveApp("another-chrome-app"));
76
77 // Non-existent value returns empty string.
78 EXPECT_EQ("", mapping()->GetChromeApp("non-existent-drive-app"));
79 EXPECT_EQ("", mapping()->GetDriveApp("non-existent-chrome-app"));
80 }
81
82 TEST_F(DriveAppMappingTest, Remove) {
83 std::set<std::string> drive_app_ids;
84
85 // Prepare data.
86 mapping()->Add("drive-1", "chrome-1");
87 mapping()->Add("drive-2", "chrome-2");
88 drive_app_ids = mapping()->GetDriveAppIds();
89 EXPECT_EQ(2u, drive_app_ids.size());
90
91 // Remove non-existent.
92 mapping()->Remove("non-existent-drive-app");
93 drive_app_ids = mapping()->GetDriveAppIds();
94 EXPECT_EQ(2u, drive_app_ids.size());
95
96 // Remove one.
97 EXPECT_EQ("chrome-1", mapping()->GetChromeApp("drive-1"));
98 mapping()->Remove("drive-1");
99 EXPECT_EQ("", mapping()->GetChromeApp("drive-1"));
100 drive_app_ids = mapping()->GetDriveAppIds();
101 EXPECT_EQ(1u, drive_app_ids.size());
102
103 // Remove it again has no effect.
104 mapping()->Remove("drive-1");
105 drive_app_ids = mapping()->GetDriveAppIds();
106 EXPECT_EQ(1u, drive_app_ids.size());
107
108 // Remove another one.
109 EXPECT_EQ("chrome-2", mapping()->GetChromeApp("drive-2"));
110 mapping()->Remove("drive-2");
111 EXPECT_EQ("", mapping()->GetChromeApp("drive-2"));
112 drive_app_ids = mapping()->GetDriveAppIds();
113 EXPECT_EQ(0u, drive_app_ids.size());
114 }
115
116 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698