Commit 4a13d5dd authored by Sebastien Lalancette's avatar Sebastien Lalancette Committed by Commit Bot

[iOS] Add "Learn More" Button to QR Code View

UX-requested functionality which allows users to learn more about what
they can do with a QR code. When tapping on the "Learn More" button, a
popover is shown with the help text.

Bug: 1064990
Change-Id: I1cc65f29607089e95c766c518fe0af526061aeb4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2218705Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Commit-Queue: Sebastien Lalancette <seblalancette@chromium.org>
Cr-Commit-Position: refs/heads/master@{#773194}
parent 06717f92
......@@ -1339,6 +1339,9 @@ Handoff must also be enabled in the General section of Settings, and your device
<message name="IDS_IOS_QR_CODE_ACTIVITY_TITLE" desc="Title format of the share view shown when sharing a QR code generated for a given Web page. [iOS only]">
QR Code: <ph name="PAGE_TITLE">$1</ph>
</message>
<message name="IDS_IOS_QR_CODE_LEARN_MORE_MESSAGE" desc="Message explaining what users can do with a generated QR code. [iOS only]">
To share with people nearby, let them scan this QR code with their camera or QR scanner app
</message>
<message name="IDS_IOS_QR_SCANNER_ALERT_CANCEL" desc="Title for a button to cancel a QR Scanner error dialog. The dialog will be dismissed and no action will be taken. [Length: 20em] [iOS only]" meaning="A button to cancel a QR Scanner error dialog.">
Cancel
</message>
......
b8da944a5ebce897c74aeb3d4f95d3ff2205398a
\ No newline at end of file
......@@ -42,6 +42,7 @@ source_set("qr_generator") {
"//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/coordinators:chrome_coordinators",
"//ios/chrome/common/ui/confirmation_alert",
"//ios/chrome/common/ui/elements:popover_label_view_controller",
"//net",
"//ui/base",
]
......@@ -62,6 +63,7 @@ source_set("unit_tests") {
"//ios/chrome/browser/main:test_support",
"//ios/chrome/browser/ui/commands",
"//ios/chrome/common/ui/confirmation_alert",
"//ios/chrome/common/ui/elements:popover_label_view_controller",
"//ios/chrome/test:test_support",
"//ios/chrome/test/fakes",
"//ios/web",
......
......@@ -16,6 +16,7 @@
#import "ios/chrome/browser/ui/commands/qr_generation_commands.h"
#import "ios/chrome/browser/ui/qr_generator/qr_generator_view_controller.h"
#import "ios/chrome/common/ui/confirmation_alert/confirmation_alert_action_handler.h"
#import "ios/chrome/common/ui/elements/popover_label_view_controller.h"
#include "ios/chrome/grit/ios_strings.h"
#import "net/base/mac/url_conversions.h"
#include "ui/base/l10n/l10n_util_mac.h"
......@@ -45,6 +46,10 @@
// Title of a page to generate a QR code for.
@property(nonatomic, copy) NSString* title;
// Popover used to show learn more info, not nil when presented.
@property(nonatomic, strong)
PopoverLabelViewController* learnMoreViewController;
@end
@implementation QRGeneratorCoordinator
......@@ -73,6 +78,7 @@
[self.viewController setPageURL:net::NSURLWithGURL(_URL)];
[self.viewController setTitleString:self.title];
[self.viewController setActionHandler:self];
[self.viewController setHelpButtonAvailable:YES];
[self.baseViewController presentViewController:self.viewController
animated:YES
......@@ -83,6 +89,7 @@
- (void)stop {
[self.viewController dismissViewControllerAnimated:YES completion:nil];
self.viewController = nil;
self.learnMoreViewController = nil;
[self.activityServiceCoordinator stop];
self.activityServiceCoordinator = nil;
......@@ -115,8 +122,19 @@
}
- (void)confirmationAlertLearnMoreAction {
// No-op.
// TODO crbug.com/1064990: Add learn more behavior.
NSString* message =
l10n_util::GetNSString(IDS_IOS_QR_CODE_LEARN_MORE_MESSAGE);
self.learnMoreViewController =
[[PopoverLabelViewController alloc] initWithMessage:message];
self.learnMoreViewController.popoverPresentationController.barButtonItem =
self.viewController.helpButton;
self.learnMoreViewController.popoverPresentationController
.permittedArrowDirections = UIPopoverArrowDirectionUp;
[self.viewController presentViewController:self.learnMoreViewController
animated:YES
completion:nil];
}
#pragma mark - ActivityServicePositioner
......
......@@ -11,7 +11,9 @@
#import "ios/chrome/browser/ui/commands/qr_generation_commands.h"
#import "ios/chrome/browser/ui/qr_generator/qr_generator_view_controller.h"
#import "ios/chrome/common/ui/confirmation_alert/confirmation_alert_action_handler.h"
#import "ios/chrome/common/ui/elements/popover_label_view_controller.h"
#import "ios/chrome/test/scoped_key_window.h"
#import "net/base/mac/url_conversions.h"
#include "testing/platform_test.h"
#import "third_party/ocmock/OCMock/OCMock.h"
#include "url/gurl.h"
......@@ -22,7 +24,9 @@
class QRGeneratorCoordinatorTest : public PlatformTest {
protected:
QRGeneratorCoordinatorTest() : browser_(std::make_unique<TestBrowser>()) {
QRGeneratorCoordinatorTest()
: test_url_("https://www.google.com/"),
browser_(std::make_unique<TestBrowser>()) {
base_view_controller_ = [[UIViewController alloc] init];
[scoped_key_window_.Get() setRootViewController:base_view_controller_];
}
......@@ -34,13 +38,26 @@ class QRGeneratorCoordinatorTest : public PlatformTest {
[browser_->GetCommandDispatcher()
startDispatchingToTarget:mock_qr_generation_commands_handler_
forProtocol:@protocol(QRGenerationCommands)];
test_title_ = @"Does not matter";
coordinator_ = [[QRGeneratorCoordinator alloc]
initWithBaseViewController:base_view_controller_
browser:browser_.get()
title:test_title_
URL:test_url_];
}
NSString* test_title_;
GURL test_url_;
base::test::TaskEnvironment task_environment_;
id mock_qr_generation_commands_handler_;
std::unique_ptr<TestBrowser> browser_;
ScopedKeyWindow scoped_key_window_;
UIViewController* base_view_controller_;
QRGeneratorCoordinator* coordinator_;
};
// Tests that a Done button gets added to the navigation bar, and its action
......@@ -49,17 +66,11 @@ TEST_F(QRGeneratorCoordinatorTest, Done_DispatchesCommand) {
// Set-up mocked handler.
[[mock_qr_generation_commands_handler_ expect] hideQRCode];
// Create and start coordinator.
QRGeneratorCoordinator* coordinator = [[QRGeneratorCoordinator alloc]
initWithBaseViewController:base_view_controller_
browser:browser_.get()
title:@"Does not matter"
URL:GURL()];
ASSERT_EQ(base_view_controller_, coordinator.baseViewController);
// Check and start coordinator.
ASSERT_EQ(base_view_controller_, coordinator_.baseViewController);
ASSERT_FALSE(base_view_controller_.presentedViewController);
[coordinator start];
[coordinator_ start];
ASSERT_TRUE(base_view_controller_.presentedViewController);
ASSERT_TRUE([base_view_controller_.presentedViewController
......@@ -69,9 +80,75 @@ TEST_F(QRGeneratorCoordinatorTest, Done_DispatchesCommand) {
base::mac::ObjCCastStrict<QRGeneratorViewController>(
base_view_controller_.presentedViewController);
// Verify some properties on the VC.
EXPECT_TRUE(viewController.helpButtonAvailable);
EXPECT_EQ(test_title_, viewController.titleString);
EXPECT_TRUE([net::NSURLWithGURL(test_url_) isEqual:viewController.pageURL]);
// Mimick click on done button.
[viewController.actionHandler confirmationAlertDone];
// Callback should've gotten invoked.
[mock_qr_generation_commands_handler_ verify];
}
// Tests that tje primary action, share, intializes the activity service
// coordinator properly.
TEST_F(QRGeneratorCoordinatorTest, ShareAction) {
[coordinator_ start];
QRGeneratorViewController* viewController =
base::mac::ObjCCastStrict<QRGeneratorViewController>(
base_view_controller_.presentedViewController);
id vcPartialMock = OCMPartialMock(viewController);
[[vcPartialMock expect]
presentViewController:[OCMArg checkWithBlock:^BOOL(
UIViewController* givenVC) {
return [givenVC isKindOfClass:[UIActivityViewController class]];
}]
animated:YES
completion:nil];
// Mimic tap on share button.
[viewController.actionHandler confirmationAlertPrimaryAction];
[vcPartialMock verify];
}
// Tests that a popover is properly created and shown when the user taps on
// the learn more button.
TEST_F(QRGeneratorCoordinatorTest, LearnMore) {
[coordinator_ start];
QRGeneratorViewController* viewController =
base::mac::ObjCCastStrict<QRGeneratorViewController>(
base_view_controller_.presentedViewController);
__block PopoverLabelViewController* popoverViewController;
id vcPartialMock = OCMPartialMock(viewController);
[[vcPartialMock expect]
presentViewController:[OCMArg checkWithBlock:^BOOL(
UIViewController* givenVC) {
if ([givenVC isKindOfClass:[PopoverLabelViewController class]]) {
popoverViewController =
base::mac::ObjCCastStrict<PopoverLabelViewController>(givenVC);
return YES;
}
return NO;
}]
animated:YES
completion:nil];
// Mimic tap on help button.
[viewController.actionHandler confirmationAlertLearnMoreAction];
[vcPartialMock verify];
EXPECT_TRUE(popoverViewController);
EXPECT_EQ(viewController.helpButton,
popoverViewController.popoverPresentationController.barButtonItem);
EXPECT_EQ(UIPopoverArrowDirectionUp,
popoverViewController.popoverPresentationController
.permittedArrowDirections);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment