def testVariationArgs(self): benchmark = perf_benchmark.PerfBenchmark() options = options_for_unittests.GetCopy() benchmark.CustomizeBrowserOptions(options.browser_options) extra_args = options.browser_options.extra_browser_args feature_args = [a for a in extra_args if a.startswith('--enable-features')] self.assertEqual(1, len(feature_args))
def testNoAdTaggingRuleset(self): benchmark = perf_benchmark.PerfBenchmark() options = options_for_unittests.GetCopy() # Set the chrome root to avoid using a ruleset from an existing "Release" # out dir. options.chrome_root = self._output_dir benchmark.CustomizeBrowserOptions(options.browser_options) self._ExpectAdTaggingProfileFiles(options.browser_options, False)
def testAdTaggingRulesetNoExplicitOutDir(self): self._PopulateGenFiles(os.path.join(self._chrome_root, 'out', 'Release')) benchmark = perf_benchmark.PerfBenchmark() options = options_for_unittests.GetCopy() options.chrome_root = self._chrome_root options.browser_options.browser_type = "release" benchmark.CustomizeOptions(options) self._ExpectAdTaggingProfileFiles(options.browser_options, True)
def testAdTaggingRulesetNoExplicitOutDirAndroidChromium(self): self._PopulateGenFiles(os.path.join(self._chrome_root, 'out', 'Default')) benchmark = perf_benchmark.PerfBenchmark() options = options_for_unittests.GetCopy() options.chrome_root = self._chrome_root # android-chromium is special cased to search for anything. options.browser_options.browser_type = "android-chromium" benchmark.CustomizeOptions(options) self._ExpectAdTaggingProfileFiles(options.browser_options, True)
def testAdTaggingRulesetOutputDirNotFound(self): # Same as the above test but use Debug instead of Release. This should # cause the benchmark to fail to find the ruleset because we only check # directories matching the browser_type. self._PopulateGenFiles(os.path.join(self._chrome_root, 'out', 'Debug')) benchmark = perf_benchmark.PerfBenchmark() options = options_for_unittests.GetCopy() options.chrome_root = self._chrome_root options.browser_options.browser_type = "release" benchmark.CustomizeOptions(options) self._ExpectAdTaggingProfileFiles(options.browser_options, False)
def testAdTaggingRuleset(self): self._PopulateGenFiles() benchmark = perf_benchmark.PerfBenchmark() options = options_for_unittests.GetCopy() # Careful, do not parse the command line flag for 'chromium-output-dir', as # that sets the global os environment variable CHROMIUM_OUTPUT_DIR, # affecting other tests. See http://crbug.com/843994. options.chromium_output_dir = self._output_dir benchmark.CustomizeOptions(options) self._ExpectAdTaggingProfileFiles(options.browser_options, True)
def testAdTaggingRulesetNoExplicitOutDir(self): # Make sure _output_dir points to Chrome's root and not the traditional # output directory. os.makedirs(os.path.join( self._output_dir, 'out','Release','gen', 'components', 'subresource_filter', 'tools','GeneratedRulesetData')) benchmark = perf_benchmark.PerfBenchmark() options = options_for_unittests.GetCopy() options.chrome_root = self._output_dir options.browser_options.browser_type = "release" benchmark.CustomizeBrowserOptions(options.browser_options) self._ExpectAdTaggingProfileFiles(options.browser_options, True)
def testAdTaggingRuleset(self): os.makedirs(os.path.join( self._output_dir, 'gen', 'components', 'subresource_filter', 'tools','GeneratedRulesetData')) benchmark = perf_benchmark.PerfBenchmark() options = options_for_unittests.GetCopy() # Careful, do not parse the command line flag for 'chromium-output-dir', as # that sets the global os environment variable CHROMIUM_OUTPUT_DIR, # affecting other tests. See http://crbug.com/843994. options.chromium_output_dir = self._output_dir benchmark.CustomizeBrowserOptions(options.browser_options) self._ExpectAdTaggingProfileFiles(options.browser_options, True)
def testAdTaggingRulesetOutputDirNotFound(self): # Same as the above test but use Debug instead of Release. This should # cause the benchmark to fail to find the ruleset because we only check # directories matching the browser_type. os.makedirs(os.path.join( self._output_dir, 'out','Debug','gen', 'components', 'subresource_filter', 'tools','GeneratedRulesetData')) benchmark = perf_benchmark.PerfBenchmark() options = options_for_unittests.GetCopy() options.chrome_root = self._output_dir options.browser_options.browser_type = "release" benchmark.CustomizeBrowserOptions(options.browser_options) self._ExpectAdTaggingProfileFiles(options.browser_options, False)
def testAdTaggingRulesetInvalidJson(self): self._PopulateGenFiles() json_path = os.path.join( self._output_dir, 'gen', 'components', 'subresource_filter', 'tools', 'default_local_state.json') self.assertTrue(os.path.exists(json_path)) with open(json_path, 'w') as f: f.write('{some invalid : json, 19') benchmark = perf_benchmark.PerfBenchmark() options = options_for_unittests.GetCopy() options.chromium_output_dir = self._output_dir # Should fail due to invalid JSON. with self.assertRaises(ValueError): benchmark.CustomizeOptions(options)
def testNoAdTaggingRuleset(self): # This tests (badly) assumes that util.GetBuildDirectories() will always # return a list of multiple directories, with Debug ordered before Release. # This is not the case if CHROMIUM_OUTPUT_DIR is set or a build.ninja file # exists in the current working directory - in those cases, only a single # directory is returned. So, abort early if we only get back one directory. num_dirs = 0 for _ in util.GetBuildDirectories(self._chrome_root): num_dirs += 1 if num_dirs < 2: return benchmark = perf_benchmark.PerfBenchmark() options = options_for_unittests.GetCopy() # Set the chrome root to avoid using a ruleset from an existing "Release" # out dir. options.chrome_root = self._output_dir benchmark.CustomizeOptions(options) self._ExpectAdTaggingProfileFiles(options.browser_options, False)
def testAdTaggingRulesetOutputDirNotFound(self): # Same as the above test but use Debug instead of Release. This should # cause the benchmark to fail to find the ruleset because we only check # directories matching the browser_type. self._PopulateGenFiles(os.path.join(self._chrome_root, 'out', 'Debug')) # This tests (badly) assumes that util.GetBuildDirectories() will always # return a list of multiple directories, with Debug ordered before Release. # This is not the case if CHROMIUM_OUTPUT_DIR is set or a build.ninja file # exists in the current working directory - in those cases, only a single # directory is returned. So, abort early if we only get back one directory. num_dirs = 0 for _ in util.GetBuildDirectories(self._chrome_root): num_dirs += 1 if num_dirs < 2: return benchmark = perf_benchmark.PerfBenchmark() options = options_for_unittests.GetCopy() options.chrome_root = self._chrome_root options.browser_options.browser_type = "release" benchmark.CustomizeOptions(options) self._ExpectAdTaggingProfileFiles(options.browser_options, False)
def testVariationArgs(self): benchmark = perf_benchmark.PerfBenchmark() options = options_for_unittests.GetCopy() options.chrome_root = self._output_dir options.browser_type = "any" possible_browser = browser_finder.FindBrowser(options) if possible_browser is None: return target_os = perf_benchmark.PerfBenchmark.FixupTargetOS( possible_browser.target_os) self.assertIsNotNone(target_os) testing_config = json.dumps({ "OtherPlatformStudy": [{ "platforms": ["fake_platform"], "experiments": [{ "name": "OtherPlatformFeature", "enable_features": ["NonExistentFeature"] }] }], "TestStudy": [{ "platforms": [target_os], "experiments": [{ "name": "TestFeature", "params": { "param1": "value1" }, "enable_features": ["Feature1", "Feature2"], "disable_features": ["Feature3", "Feature4"] }] }] }) variations_dir = os.path.join(self._output_dir, "testing", "variations") os.makedirs(variations_dir) fieldtrial_path = os.path.join(variations_dir, "fieldtrial_testing_config.json") with open(fieldtrial_path, "w") as f: f.write(testing_config) benchmark.CustomizeBrowserOptions(options.browser_options) expected_args = [ "--enable-features=Feature1<TestStudy,Feature2<TestStudy", "--disable-features=Feature3<TestStudy,Feature4<TestStudy", "--force-fieldtrials=TestStudy/TestFeature", "--force-fieldtrial-params=TestStudy.TestFeature:param1/value1" ] for arg in expected_args: self.assertIn(arg, options.browser_options.extra_browser_args) # Test 'reference' type, which has no variation params applied by default. benchmark = perf_benchmark.PerfBenchmark() options = options_for_unittests.GetCopy() options.chrome_root = self._output_dir options.browser_options.browser_type = 'reference' benchmark.CustomizeBrowserOptions(options.browser_options) for arg in expected_args: self.assertNotIn(arg, options.browser_options.extra_browser_args) # Test compatibility mode, which has no variation params applied by default. benchmark = perf_benchmark.PerfBenchmark() options = options_for_unittests.GetCopy() options.chrome_root = self._output_dir options.browser_options.compatibility_mode = True benchmark.CustomizeBrowserOptions(options.browser_options) for arg in expected_args: self.assertNotIn(arg, options.browser_options.extra_browser_args)
def testNoAdTaggingRuleset(self): benchmark = perf_benchmark.PerfBenchmark() options = options_for_unittests.GetCopy() benchmark.CustomizeBrowserOptions(options.browser_options) self._ExpectAdTaggingProfileFiles(options.browser_options, False)