1 // Copyright 2012 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.
5 #import "ios/chrome/browser/ui/commands/set_up_for_testing_command.h"
7 #include "base/logging.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "ios/chrome/browser/ui/commands/ios_command_ids.h"
10 #include "net/base/url_util.h"
14 // Clear all browsing data.
15 const char kClearBrowsingData[] = "clearBrowsingData";
16 // Close existing tabs.
17 const char kCloseTabs[] = "closeTabs";
18 // Number of new tabs.
19 const char kNumberOfNewTabs[] = "numberOfNewTabs";
22 @implementation SetUpForTestingCommand
24 @synthesize clearBrowsingData = _clearBrowsingData;
25 @synthesize closeTabs = _closeTabs;
26 @synthesize numberOfNewTabs = _numberOfNewTabs;
28 - (instancetype)initWithTag:(NSInteger)tag {
33 - (instancetype)initWithURL:(const GURL&)url {
35 int numberOfNewTabs = 0;
36 if (net::GetValueForKeyInQuery(url, kNumberOfNewTabs, &value)) {
37 if (!base::StringToInt(value, &numberOfNewTabs) || numberOfNewTabs < 0) {
38 // Ignore incorrect value for "numberOfNewTabs".
43 bool clearBrowsingData =
44 net::GetValueForKeyInQuery(url, kClearBrowsingData, &ignored);
45 bool closeTabs = net::GetValueForKeyInQuery(url, kCloseTabs, &ignored);
46 return [self initWithClearBrowsingData:clearBrowsingData
48 numberOfNewTabs:numberOfNewTabs];
51 - (instancetype)initWithClearBrowsingData:(BOOL)clearBrowsingData
52 closeTabs:(BOOL)closeTabs
53 numberOfNewTabs:(NSInteger)numberOfNewTabs {
54 self = [super initWithTag:IDC_SETUP_FOR_TESTING];
56 _clearBrowsingData = clearBrowsingData;
57 _closeTabs = closeTabs;
58 _numberOfNewTabs = numberOfNewTabs;