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

Side by Side Diff: components/arc/intent_helper/open_with_menu_observer_unittest.cc

Issue 1760773004: Add "Open with <ARC-app-name>" items to the context menu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add a missing override; Created 4 years, 8 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
OLDNEW
(Empty)
1 // Copyright 2016 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 "base/strings/stringprintf.h"
6 #include "components/arc/intent_helper/open_with_menu_observer.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace arc {
10
11 namespace {
12
13 // All tests in this file assume that 4 and 10 IDC command IDs are reserved
14 // for the main and sub menus, respectively.
15 const int kFirstMainMenuId = 0x12345;
16 const int kFirstSubMenuId = 0x23456;
17
18 std::pair<OpenWithMenuObserver::HandlerMap, int> BuildHandlersMap(
19 size_t num_apps) {
20 mojo::Array<UrlHandlerInfoPtr> handlers;
21 for (size_t i = 0; i < num_apps; ++i) {
22 UrlHandlerInfoPtr p = UrlHandlerInfo::New();
23 p->name = base::StringPrintf("App %zu", i);
24 handlers.push_back(std::move(p));
25 }
26 return OpenWithMenuObserver::BuildHandlersMapForTesting(
27 kFirstMainMenuId, 4, kFirstSubMenuId, 10, std::move(handlers));
28 }
29
30 } // namespace
31
32 TEST(OpenWithMenuObserverTest, TestGetCommandIdsToEnable) {
33 auto result = BuildHandlersMap(0);
34 EXPECT_EQ(0U, result.first.size());
35 EXPECT_EQ(-1, result.second);
36
37 result = BuildHandlersMap(1);
38 ASSERT_EQ(1U, result.first.size());
39 ASSERT_EQ(1U, result.first.count(kFirstMainMenuId));
40 EXPECT_EQ(-1, result.second);
41 EXPECT_EQ("App 0", result.first[kFirstMainMenuId]->name);
42
43 result = BuildHandlersMap(2);
44 EXPECT_EQ(2U, result.first.size());
45 ASSERT_EQ(1U, result.first.count(kFirstMainMenuId));
46 ASSERT_EQ(1U, result.first.count(kFirstMainMenuId + 1));
47 EXPECT_EQ(-1, result.second);
48 EXPECT_EQ("App 0", result.first[kFirstMainMenuId]->name);
49 EXPECT_EQ("App 1", result.first[kFirstMainMenuId + 1]->name);
50
51 result = BuildHandlersMap(3);
52 EXPECT_EQ(3U, result.first.size());
53 ASSERT_EQ(1U, result.first.count(kFirstMainMenuId));
54 ASSERT_EQ(1U, result.first.count(kFirstMainMenuId + 1));
55 ASSERT_EQ(1U, result.first.count(kFirstMainMenuId + 2));
56 EXPECT_EQ(-1, result.second);
57 EXPECT_EQ("App 0", result.first[kFirstMainMenuId]->name);
58 EXPECT_EQ("App 1", result.first[kFirstMainMenuId + 1]->name);
59 EXPECT_EQ("App 2", result.first[kFirstMainMenuId + 2]->name);
60
61 // Test if app names will overflow to the sub menu.
62 result = BuildHandlersMap(4);
63 EXPECT_EQ(4U, result.first.size());
64 ASSERT_EQ(1U, result.first.count(kFirstMainMenuId));
65 ASSERT_EQ(1U, result.first.count(kFirstMainMenuId + 1));
66 // In this case, kFirstMainMenuId + 2 should be hidden.
67 EXPECT_EQ(kFirstMainMenuId + 3, result.second);
68 ASSERT_EQ(1U, result.first.count(kFirstSubMenuId));
69 ASSERT_EQ(1U, result.first.count(kFirstSubMenuId + 1));
70 EXPECT_EQ("App 0", result.first[kFirstMainMenuId]->name);
71 EXPECT_EQ("App 1", result.first[kFirstMainMenuId + 1]->name);
72 EXPECT_EQ("App 2", result.first[kFirstSubMenuId]->name);
73 EXPECT_EQ("App 3", result.first[kFirstSubMenuId + 1]->name);
74
75 result = BuildHandlersMap(11);
76 EXPECT_EQ(11U, result.first.size());
77 ASSERT_EQ(1U, result.first.count(kFirstMainMenuId));
78 ASSERT_EQ(1U, result.first.count(kFirstMainMenuId + 1));
79 EXPECT_EQ(kFirstMainMenuId + 3, result.second);
80 EXPECT_EQ("App 0", result.first[kFirstMainMenuId]->name);
81 EXPECT_EQ("App 1", result.first[kFirstMainMenuId + 1]->name);
82 for (size_t i = 0; i < 9; ++i) {
83 ASSERT_EQ(1U, result.first.count(kFirstSubMenuId + i)) << i;
84 }
85
86 // The main and sub menus can show up to 12 (=3+10-1) app names.
87 result = BuildHandlersMap(12);
88 EXPECT_EQ(12U, result.first.size());
89 ASSERT_EQ(1U, result.first.count(kFirstMainMenuId));
90 ASSERT_EQ(1U, result.first.count(kFirstMainMenuId + 1));
91 EXPECT_EQ(kFirstMainMenuId + 3, result.second);
92 EXPECT_EQ("App 0", result.first[kFirstMainMenuId]->name);
93 EXPECT_EQ("App 1", result.first[kFirstMainMenuId + 1]->name);
94 for (size_t i = 0; i < 10; ++i) {
95 const int id = kFirstSubMenuId + i;
96 ASSERT_EQ(1U, result.first.count(id)) << i;
97 EXPECT_EQ(base::StringPrintf("App %zu", i + 2), result.first[id]->name)
98 << i;
99 }
100
101 result = BuildHandlersMap(13);
102 EXPECT_EQ(12U, result.first.size()); // still 12
103 ASSERT_EQ(1U, result.first.count(kFirstMainMenuId));
104 ASSERT_EQ(1U, result.first.count(kFirstMainMenuId + 1));
105 EXPECT_EQ(kFirstMainMenuId + 3, result.second);
106 EXPECT_EQ("App 0", result.first[kFirstMainMenuId]->name);
107 EXPECT_EQ("App 1", result.first[kFirstMainMenuId + 1]->name);
108 for (size_t i = 0; i < 10; ++i) { // still 10
109 const int id = kFirstSubMenuId + i;
110 ASSERT_EQ(1U, result.first.count(id)) << i;
111 EXPECT_EQ(base::StringPrintf("App %zu", i + 2), result.first[id]->name)
112 << i;
113 }
114
115 result = BuildHandlersMap(1000);
116 EXPECT_EQ(12U, result.first.size()); // still 12
117 ASSERT_EQ(1U, result.first.count(kFirstMainMenuId));
118 ASSERT_EQ(1U, result.first.count(kFirstMainMenuId + 1));
119 EXPECT_EQ(kFirstMainMenuId + 3, result.second);
120 EXPECT_EQ("App 0", result.first[kFirstMainMenuId]->name);
121 EXPECT_EQ("App 1", result.first[kFirstMainMenuId + 1]->name);
122 for (size_t i = 0; i < 10; ++i) { // still 10
123 const int id = kFirstSubMenuId + i;
124 ASSERT_EQ(1U, result.first.count(id)) << i;
125 EXPECT_EQ(base::StringPrintf("App %zu", i + 2), result.first[id]->name)
126 << i;
127 }
128 }
129
130 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698