1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53

content / test / data / shared_storage / simple_module.js [blame]

// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

console.log('Start executing simple_module.js')

class TestOperation {
  async run(data) {
    console.log('Start executing \'test-operation\'');
    if (data === undefined || data === null) {
      console.log(data);
    } else if (data.constructor.name === 'CryptoKey') {
      console.log(
        "CryptoKey,",
        "algorithm:",
        JSON.stringify(data.algorithm, Object.keys(data.algorithm).sort()),
        "usages:",
        JSON.stringify(data.usages, Object.keys(data.usages).sort()),
        "extractable:", data.extractable);
    } else {
      console.log(JSON.stringify(data, Object.keys(data).sort()));
    }
    console.log('Finish executing \'test-operation\'');
  }
}

class TestURLSelectionOperation {
  async run(urls, data) {
    console.log('Start executing \'test-url-selection-operation\'');
    console.log(JSON.stringify(urls));
    console.log(JSON.stringify(data, Object.keys(data).sort()));
    console.log('Finish executing \'test-url-selection-operation\'');

    if (data && data.hasOwnProperty('mockResult')) {
      return data['mockResult'];
    }

    return -1;
  }
}

class RemainingBudgetOperation {
  async run(data) {
    console.log('remaining budget: ' +
                (await sharedStorage.remainingBudget()).toString());
  }
}

register("test-operation", TestOperation);
register("test-url-selection-operation", TestURLSelectionOperation);
register("remaining-budget-operation", RemainingBudgetOperation);

console.log('Finish executing simple_module.js')