Skip to content

Commit

Permalink
Enable CRX file unit tests for Evergreen builds (youtube#717)
Browse files Browse the repository at this point in the history
It'll be particularly helpful to have these tests in place as we get
ready to make changes to CRX verification for in-memory updates.

The test CRX files were downloaded from the Chromium repository and
uploaded to Cobalt's static storage GCS bucket.

b/158043520

Change-Id: I9657ff968046bcd5cc8fd63aeee0f0c8433f4703
  • Loading branch information
hlwarriner authored Jun 28, 2023
1 parent 61b3790 commit 6904c86
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 2 deletions.
60 changes: 60 additions & 0 deletions components/crx_file/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

if (is_starboard) {
import("//components/crx_file/testdata/sha1_files.gni")
}
import("//third_party/protobuf/proto_library.gni")

# The accompanying crx_creator target has been left behind during the migration
Expand All @@ -35,3 +38,60 @@ static_library("crx_file") {
"//third_party/protobuf:protobuf_lite",
]
}

if (is_starboard) {
action("crx_file_download_test_data") {
install_content = true

script = "//tools/download_from_gcs.py"

sha_sources = []
foreach(sha1_file, sha1_files) {
sha_sources += [ string_join("/",
[
"testdata",
sha1_file,
]) ]
}

sha_outputs = []
subdir = "components/crx_file"
outdir = "$sb_static_contents_output_data_dir/test/$subdir"
foreach(sha_source, sha_sources) {
sha_outputs += [ string_join("/",
[
outdir,
string_replace(sha_source, ".sha1", ""),
]) ]
}

sources = sha_sources
outputs = sha_outputs

sha1_dir = rebase_path("testdata", root_build_dir)

args = [
"--bucket",
"cobalt-static-storage",
"--sha1",
sha1_dir,
"--output",
rebase_path("$outdir/testdata", root_build_dir),
]
}

target(gtest_target_type, "crx_file_test") {
testonly = true

sources = [ "crx_verifier_unittest.cc" ]

deps = [
":crx_file",
"//cobalt/test:run_all_unittests",
"//starboard:starboard_headers_only",
"//testing/gtest",
]

data_deps = [ ":crx_file_download_test_data" ]
}
}
16 changes: 15 additions & 1 deletion components/crx_file/crx_verifier_unittest.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Copyright 2017 The Cobalt Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand All @@ -7,18 +7,32 @@
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "base/strings/string_number_conversions.h"
#if defined(STARBOARD)
#include "starboard/system.h"
#endif
#include "testing/gtest/include/gtest/gtest.h"

namespace {

base::FilePath TestFile(const std::string& file) {
#if defined(STARBOARD)
std::vector<char> buf(kSbFileMaxPath);
SbSystemGetPath(kSbSystemPathContentDirectory, buf.data(), kSbFileMaxPath);
return base::FilePath(buf.data())
.AppendASCII("test")
.AppendASCII("components")
.AppendASCII("crx_file")
.AppendASCII("testdata")
.AppendASCII(file);
#else
base::FilePath path;
base::PathService::Get(base::DIR_SOURCE_ROOT, &path);
return path.AppendASCII("components")
.AppendASCII("test")
.AppendASCII("data")
.AppendASCII("crx_file")
.AppendASCII(file);
#endif
}

constexpr char kOjjHash[] = "ojjgnpkioondelmggbekfhllhdaimnho";
Expand Down
21 changes: 21 additions & 0 deletions components/crx_file/testdata/sha1_files.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2023 The Cobalt Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

sha1_files = [
"unsigned.crx3.sha1",
"valid.crx2.sha1",
"valid_no_publisher.crx3.sha1",
"valid_publisher.crx3.sha1",
"valid_test_publisher.crx3.sha1",
]
1 change: 1 addition & 0 deletions components/crx_file/testdata/unsigned.crx3.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ad85238e7e3afe325e6be902aeb018e0d14fe3de
1 change: 1 addition & 0 deletions components/crx_file/testdata/valid.crx2.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6bd2e7950cdb59ad8d2fc53bdc43be1c207e8173
1 change: 1 addition & 0 deletions components/crx_file/testdata/valid_no_publisher.crx3.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
baf9dd313fa5c4228fe05cce3d292bd6d7006342
1 change: 1 addition & 0 deletions components/crx_file/testdata/valid_publisher.crx3.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6fbbf33b4ad56ff25608f975fc78840eb41be1ba
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9059d7419401f8764d6788006747f3407fdba6f0
6 changes: 5 additions & 1 deletion starboard/evergreen/shared/gyp_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ def GetLauncherPath(self):

def GetTestTargets(self):
tests = super().GetTestTargets()
tests.extend({'cobalt_slot_management_test', 'updater_test'})
tests.extend({
'cobalt_slot_management_test',
'crx_file_test',
'updater_test',
})
return [test for test in tests if test not in self.__FORBIDDEN_TESTS]

__FORBIDDEN_TESTS = [ # pylint: disable=invalid-name
Expand Down

0 comments on commit 6904c86

Please sign in to comment.