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

Unified Diff: chrome/browser/renderer_context_menu/arc_app_menu_observer_chromeos_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: address comments Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/renderer_context_menu/arc_app_menu_observer_chromeos_unittest.cc
diff --git a/chrome/browser/renderer_context_menu/arc_app_menu_observer_chromeos_unittest.cc b/chrome/browser/renderer_context_menu/arc_app_menu_observer_chromeos_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a1480da70793abca87cca33a81fdab0b978db520
--- /dev/null
+++ b/chrome/browser/renderer_context_menu/arc_app_menu_observer_chromeos_unittest.cc
@@ -0,0 +1,184 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/app/chrome_command_ids.h"
+#include "chrome/browser/renderer_context_menu/arc_app_menu_observer_chromeos.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+TEST(ArcAppMenuObserverTest, TestGetIndexForCommandId) {
+ // All tests in this file assume that 3 and 10 IDC command IDs are reserved
+ // for the main and sub menus, respectively.
+ ASSERT_EQ(
+ 3, IDC_CONTENT_CONTEXT_ARC_APP_LAST - IDC_CONTENT_CONTEXT_ARC_APP1 + 1);
+ ASSERT_EQ(10, IDC_CONTENT_CONTEXT_ARC_SUB_APP_LAST -
+ IDC_CONTENT_CONTEXT_ARC_SUB_APP1 + 1);
+
+ EXPECT_EQ(0, ArcAppMenuObserver::GetIndexForCommandIdForTesting(
+ IDC_CONTENT_CONTEXT_ARC_APP1));
+ EXPECT_EQ(1, ArcAppMenuObserver::GetIndexForCommandIdForTesting(
+ IDC_CONTENT_CONTEXT_ARC_APP2));
+ EXPECT_EQ(2, ArcAppMenuObserver::GetIndexForCommandIdForTesting(
+ IDC_CONTENT_CONTEXT_ARC_APP3));
+ EXPECT_EQ(-1, ArcAppMenuObserver::GetIndexForCommandIdForTesting(
+ IDC_CONTENT_CONTEXT_ARC_SUB_MENU));
+ EXPECT_EQ(2, ArcAppMenuObserver::GetIndexForCommandIdForTesting(
+ IDC_CONTENT_CONTEXT_ARC_SUB_APP1)); // not 3
+ EXPECT_EQ(3, ArcAppMenuObserver::GetIndexForCommandIdForTesting(
+ IDC_CONTENT_CONTEXT_ARC_SUB_APP2));
+ EXPECT_EQ(4, ArcAppMenuObserver::GetIndexForCommandIdForTesting(
+ IDC_CONTENT_CONTEXT_ARC_SUB_APP3));
+ EXPECT_EQ(5, ArcAppMenuObserver::GetIndexForCommandIdForTesting(
+ IDC_CONTENT_CONTEXT_ARC_SUB_APP4));
+ EXPECT_EQ(6, ArcAppMenuObserver::GetIndexForCommandIdForTesting(
+ IDC_CONTENT_CONTEXT_ARC_SUB_APP5));
+ EXPECT_EQ(7, ArcAppMenuObserver::GetIndexForCommandIdForTesting(
+ IDC_CONTENT_CONTEXT_ARC_SUB_APP6));
+ EXPECT_EQ(8, ArcAppMenuObserver::GetIndexForCommandIdForTesting(
+ IDC_CONTENT_CONTEXT_ARC_SUB_APP7));
+ EXPECT_EQ(9, ArcAppMenuObserver::GetIndexForCommandIdForTesting(
+ IDC_CONTENT_CONTEXT_ARC_SUB_APP8));
+ EXPECT_EQ(10, ArcAppMenuObserver::GetIndexForCommandIdForTesting(
+ IDC_CONTENT_CONTEXT_ARC_SUB_APP9));
+ EXPECT_EQ(11, ArcAppMenuObserver::GetIndexForCommandIdForTesting(
+ IDC_CONTENT_CONTEXT_ARC_SUB_APP10));
+
+ // Test with unknown ID.
+ EXPECT_EQ(-1, ArcAppMenuObserver::GetIndexForCommandIdForTesting(
+ IDC_CONTENT_CONTEXT_SEARCHWEBFOR));
+}
+
+TEST(ArcAppMenuObserverTest, TestGetCommandIdsToEnable) {
+ std::set<int> result = ArcAppMenuObserver::GetCommandIdsToEnableForTesting(0);
+ EXPECT_EQ(0U, result.size());
+
+ result = ArcAppMenuObserver::GetCommandIdsToEnableForTesting(1);
+ EXPECT_EQ(1U, result.size());
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP1));
+
+ result = ArcAppMenuObserver::GetCommandIdsToEnableForTesting(2);
+ EXPECT_EQ(2U, result.size());
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP1));
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP2));
+
+ result = ArcAppMenuObserver::GetCommandIdsToEnableForTesting(3);
+ EXPECT_EQ(3U, result.size());
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP1));
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP2));
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP3));
+
+ // Test if app names will overflow to the sub menu.
+ result = ArcAppMenuObserver::GetCommandIdsToEnableForTesting(4);
+ EXPECT_EQ(5U, result.size()); // app names and "More"
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP1));
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP2));
+ // In this case, IDC_CONTENT_CONTEXT_ARC_APP3 should be hidden.
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_SUB_MENU));
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_SUB_APP1));
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_SUB_APP2));
+
+ result = ArcAppMenuObserver::GetCommandIdsToEnableForTesting(11);
+ EXPECT_EQ(12U, result.size());
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP1));
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP2));
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_SUB_MENU));
+ for (size_t i = 0; i < 9; ++i) {
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_SUB_APP1 + i)) << i;
+ }
+
+ // The main and sub menus can show up to 12 (=3+10-1) app names.
+ result = ArcAppMenuObserver::GetCommandIdsToEnableForTesting(12);
+ EXPECT_EQ(13U, result.size());
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP1));
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP2));
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_SUB_MENU));
+ for (size_t i = 0; i < 10; ++i) {
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_SUB_APP1 + i)) << i;
+ }
+
+ result = ArcAppMenuObserver::GetCommandIdsToEnableForTesting(13);
+ EXPECT_EQ(13U, result.size()); // still 13
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP1));
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP2));
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_SUB_MENU));
+ for (size_t i = 0; i < 10; ++i) { // still 10
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_SUB_APP1 + i)) << i;
+ }
+
+ result = ArcAppMenuObserver::GetCommandIdsToEnableForTesting(1000);
+ EXPECT_EQ(13U, result.size()); // still 13
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP1));
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP2));
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_SUB_MENU));
+ for (size_t i = 0; i < 10; ++i) { // still 10
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_SUB_APP1 + i)) << i;
+ }
+}
+
+TEST(ArcAppMenuObserverTest, TestGetCommandIdsToDisable) {
+ std::set<int> result =
+ ArcAppMenuObserver::GetCommandIdsToDisableForTesting(0);
+ // 3 items for the main menu, 1 item for "More", and 10 items for the sub
+ // menu. 14 in total.
+ EXPECT_EQ(14U, result.size());
+
+ result = ArcAppMenuObserver::GetCommandIdsToDisableForTesting(1);
+ EXPECT_EQ(13U, result.size());
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP2));
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP3));
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_SUB_MENU));
+ for (size_t i = 0; i < 10; ++i) {
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_SUB_APP1 + i)) << i;
+ }
+
+ result = ArcAppMenuObserver::GetCommandIdsToDisableForTesting(2);
+ EXPECT_EQ(12U, result.size());
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP3));
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_SUB_MENU));
+ for (size_t i = 0; i < 10; ++i) {
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_SUB_APP1 + i)) << i;
+ }
+
+ result = ArcAppMenuObserver::GetCommandIdsToDisableForTesting(3);
+ EXPECT_EQ(11U, result.size());
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_SUB_MENU));
+ for (size_t i = 0; i < 10; ++i) {
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_SUB_APP1 + i)) << i;
+ }
+
+ result = ArcAppMenuObserver::GetCommandIdsToDisableForTesting(4);
+ // The first 2 items in the main menu, "More", and the first 2 items in the
+ // sub menu are enalbed, hence 9 (=14-(2+1+2)).
+ EXPECT_EQ(9U, result.size());
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP3));
+ for (size_t i = 2; i < 10; ++i) {
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_SUB_APP1 + i)) << i;
+ }
+
+ result = ArcAppMenuObserver::GetCommandIdsToDisableForTesting(11);
+ EXPECT_EQ(2U, result.size());
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP3));
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_SUB_APP10));
+
+ result = ArcAppMenuObserver::GetCommandIdsToDisableForTesting(12);
+ EXPECT_EQ(1U, result.size());
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP3));
+
+ result = ArcAppMenuObserver::GetCommandIdsToDisableForTesting(13);
+ EXPECT_EQ(1U, result.size());
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP3));
+
+ result = ArcAppMenuObserver::GetCommandIdsToDisableForTesting(1000);
+ EXPECT_EQ(1U, result.size());
+ EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP3));
+}
+
+TEST(ArcAppMenuObserverTest, TestGetCommandIdsToEnableDisable) {
+ for (int apps = 0; apps < 20; ++apps) {
+ const size_t enabled =
+ ArcAppMenuObserver::GetCommandIdsToEnableForTesting(apps).size();
+ const size_t disabled =
+ ArcAppMenuObserver::GetCommandIdsToDisableForTesting(apps).size();
+ EXPECT_EQ(14U, enabled + disabled) << apps;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698