Chromium Code Reviews| 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" | |
|
Eugene But (OOO till 7-30)
2017/03/06 23:02:06
Linebreak after this
liaoyuke
2017/03/07 01:02:43
Done.
| |
| 6 #include "base/mac/scoped_nsobject.h" | |
|
Eugene But (OOO till 7-30)
2017/03/06 23:02:06
import
liaoyuke
2017/03/07 01:02:43
Done.
| |
| 7 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" | |
| 8 #import "ios/chrome/browser/ui/tools_menu/tools_menu_configuration.h" | |
| 9 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_item.h" | |
| 10 #include "ios/web/public/user_agent.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | |
| 12 #include "testing/platform_test.h" | |
| 13 | |
| 14 @interface ToolsMenuViewController (ExposedForTesting) | |
|
Eugene But (OOO till 7-30)
2017/03/06 23:02:06
From "Unit Testing Best Practices": Test code usin
liaoyuke
2017/03/07 01:02:43
Thanks for explaining using links, they are really
| |
| 15 @property(nonatomic, retain) NSMutableArray* menuItems; | |
| 16 @end | |
| 17 | |
| 18 class ToolsMenuViewControllerTest : public PlatformTest { | |
| 19 protected: | |
| 20 void SetUp() override { | |
| 21 PlatformTest::SetUp(); | |
| 22 _configuration.reset( | |
| 23 [[ToolsMenuConfiguration alloc] initWithDisplayView:nil]); | |
| 24 _controller.reset([[ToolsMenuViewController alloc] init]); | |
| 25 } | |
| 26 | |
| 27 void TearDown() override { | |
| 28 _configuration.reset(); | |
|
Eugene But (OOO till 7-30)
2017/03/06 23:02:06
Is this necessary?
liaoyuke
2017/03/07 01:02:43
Done.
| |
| 29 _controller.reset(); | |
| 30 PlatformTest::TearDown(); | |
| 31 } | |
| 32 | |
| 33 // Returns tools menu view item by IDC value, null if not exit. | |
| 34 ToolsMenuViewItem* GetToolsMenuViewItemWithTag(int tag) { | |
| 35 for (ToolsMenuViewItem* item in [_controller menuItems]) { | |
| 36 if ([item tag] == tag) | |
| 37 return item; | |
| 38 } | |
| 39 | |
| 40 return nullptr; | |
| 41 } | |
| 42 | |
| 43 base::scoped_nsobject<ToolsMenuConfiguration> _configuration; | |
|
Eugene But (OOO till 7-30)
2017/03/06 23:02:06
configuration_
liaoyuke
2017/03/07 01:02:43
Done.
| |
| 44 base::scoped_nsobject<ToolsMenuViewController> _controller; | |
| 45 }; | |
| 46 | |
| 47 // Tests that "Request Desktop Site" is visible and enabled, and | |
| 48 // "Request Mobile Site" is invisible when the current page is a native page, | |
| 49 // whose user agent type is NONE. | |
| 50 TEST_F(ToolsMenuViewControllerTest, TestUserAgentTypeNONE) { | |
| 51 [_configuration setUserAgentType:web::UserAgentType::NONE]; | |
| 52 [_controller initializeMenuWithConfiguration:_configuration.get()]; | |
| 53 | |
| 54 ToolsMenuViewItem* desktop_item = | |
| 55 GetToolsMenuViewItemWithTag(IDC_REQUEST_DESKTOP_SITE); | |
| 56 ASSERT_TRUE(desktop_item); | |
| 57 EXPECT_FALSE(desktop_item.active); | |
| 58 | |
| 59 ToolsMenuViewItem* mobile_item = | |
| 60 GetToolsMenuViewItemWithTag(IDC_REQUEST_MOBILE_SITE); | |
| 61 EXPECT_FALSE(mobile_item); | |
| 62 } | |
| 63 | |
| 64 // Tests that "Request Desktop Site" is visible and not enabled, and | |
| 65 // "Request Mobile Site" is invisible when the current page is a web page and | |
| 66 // uses MOBILE user agent. | |
| 67 TEST_F(ToolsMenuViewControllerTest, TestUserAgentTypeMOBILE) { | |
| 68 [_configuration setUserAgentType:web::UserAgentType::MOBILE]; | |
| 69 [_controller initializeMenuWithConfiguration:_configuration.get()]; | |
| 70 | |
| 71 ToolsMenuViewItem* desktop_item = | |
| 72 GetToolsMenuViewItemWithTag(IDC_REQUEST_DESKTOP_SITE); | |
| 73 ASSERT_TRUE(desktop_item); | |
| 74 EXPECT_TRUE(desktop_item.active); | |
| 75 | |
| 76 ToolsMenuViewItem* mobile_item = | |
| 77 GetToolsMenuViewItemWithTag(IDC_REQUEST_MOBILE_SITE); | |
| 78 EXPECT_FALSE(mobile_item); | |
| 79 } | |
| 80 | |
| 81 // Tests that "Request Desktop Site" is invisible, and "Request Mobile Site" is | |
| 82 // visible and enabled when the current page is a web page and uses DESKTOP user | |
| 83 // agent. | |
| 84 TEST_F(ToolsMenuViewControllerTest, TestUserAgentTypeDESKTOP) { | |
| 85 [_configuration setUserAgentType:web::UserAgentType::DESKTOP]; | |
| 86 [_controller initializeMenuWithConfiguration:_configuration.get()]; | |
| 87 | |
| 88 ToolsMenuViewItem* mobile_item = | |
| 89 GetToolsMenuViewItemWithTag(IDC_REQUEST_MOBILE_SITE); | |
| 90 ASSERT_TRUE(mobile_item); | |
| 91 EXPECT_TRUE(mobile_item.active); | |
| 92 | |
| 93 ToolsMenuViewItem* desktop_item = | |
| 94 GetToolsMenuViewItemWithTag(IDC_REQUEST_DESKTOP_SITE); | |
| 95 EXPECT_FALSE(desktop_item); | |
| 96 } | |
| OLD | NEW |