| OLD | NEW |
| (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 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_controller.h" |
| 6 |
| 7 #import "base/mac/scoped_nsobject.h" |
| 8 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" |
| 9 #import "ios/chrome/browser/ui/tools_menu/tools_menu_configuration.h" |
| 10 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_item.h" |
| 11 #include "ios/web/public/user_agent.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "testing/platform_test.h" |
| 14 |
| 15 class ToolsMenuViewControllerTest : public PlatformTest { |
| 16 protected: |
| 17 void SetUp() override { |
| 18 PlatformTest::SetUp(); |
| 19 configuration_.reset( |
| 20 [[ToolsMenuConfiguration alloc] initWithDisplayView:nil]); |
| 21 controller_.reset([[ToolsMenuViewController alloc] init]); |
| 22 } |
| 23 |
| 24 // Returns tools menu view item by IDC value, null if not exit. |
| 25 ToolsMenuViewItem* GetToolsMenuViewItemWithTag(int tag) { |
| 26 for (ToolsMenuViewItem* item in [controller_ menuItems]) { |
| 27 if ([item tag] == tag) |
| 28 return item; |
| 29 } |
| 30 |
| 31 return nullptr; |
| 32 } |
| 33 |
| 34 base::scoped_nsobject<ToolsMenuConfiguration> configuration_; |
| 35 base::scoped_nsobject<ToolsMenuViewController> controller_; |
| 36 }; |
| 37 |
| 38 // Tests that "Request Desktop Site" is visible and enabled, and |
| 39 // "Request Mobile Site" is invisible when the current page is a native page, |
| 40 // whose user agent type is NONE. |
| 41 TEST_F(ToolsMenuViewControllerTest, TestUserAgentTypeNONE) { |
| 42 [configuration_ setUserAgentType:web::UserAgentType::NONE]; |
| 43 [controller_ initializeMenuWithConfiguration:configuration_.get()]; |
| 44 |
| 45 ToolsMenuViewItem* desktop_item = |
| 46 GetToolsMenuViewItemWithTag(IDC_REQUEST_DESKTOP_SITE); |
| 47 ASSERT_TRUE(desktop_item); |
| 48 EXPECT_FALSE(desktop_item.active); |
| 49 |
| 50 ToolsMenuViewItem* mobile_item = |
| 51 GetToolsMenuViewItemWithTag(IDC_REQUEST_MOBILE_SITE); |
| 52 EXPECT_FALSE(mobile_item); |
| 53 } |
| 54 |
| 55 // Tests that "Request Desktop Site" is visible and not enabled, and |
| 56 // "Request Mobile Site" is invisible when the current page is a web page and |
| 57 // uses MOBILE user agent. |
| 58 TEST_F(ToolsMenuViewControllerTest, TestUserAgentTypeMOBILE) { |
| 59 [configuration_ setUserAgentType:web::UserAgentType::MOBILE]; |
| 60 [controller_ initializeMenuWithConfiguration:configuration_.get()]; |
| 61 |
| 62 ToolsMenuViewItem* desktop_item = |
| 63 GetToolsMenuViewItemWithTag(IDC_REQUEST_DESKTOP_SITE); |
| 64 ASSERT_TRUE(desktop_item); |
| 65 EXPECT_TRUE(desktop_item.active); |
| 66 |
| 67 ToolsMenuViewItem* mobile_item = |
| 68 GetToolsMenuViewItemWithTag(IDC_REQUEST_MOBILE_SITE); |
| 69 EXPECT_FALSE(mobile_item); |
| 70 } |
| 71 |
| 72 // Tests that "Request Desktop Site" is visible and not enabled, and |
| 73 // "Request Mobile Site" is invisible when the current page is a web page and |
| 74 // uses DESKTOP user agent. |
| 75 TEST_F(ToolsMenuViewControllerTest, TestUserAgentTypeDESKTOP) { |
| 76 [configuration_ setUserAgentType:web::UserAgentType::DESKTOP]; |
| 77 [controller_ initializeMenuWithConfiguration:configuration_.get()]; |
| 78 |
| 79 ToolsMenuViewItem* desktop_item = |
| 80 GetToolsMenuViewItemWithTag(IDC_REQUEST_DESKTOP_SITE); |
| 81 ASSERT_TRUE(desktop_item); |
| 82 EXPECT_FALSE(desktop_item.active); |
| 83 |
| 84 ToolsMenuViewItem* mobile_item = |
| 85 GetToolsMenuViewItemWithTag(IDC_REQUEST_MOBILE_SITE); |
| 86 EXPECT_FALSE(mobile_item); |
| 87 } |
| OLD | NEW |