tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_script_loader_js_cache_basic.js (10624B)


      1 // ev, unordered, and runJSCacheTests are defined in head.js
      2 
      3 add_task(async function testDiskCache() {
      4  await SpecialPowers.pushPrefEnv({
      5    set: [
      6      ["dom.expose_test_interfaces", true],
      7      ["dom.script_loader.bytecode_cache.enabled", true],
      8      ["dom.script_loader.bytecode_cache.strategy", 0],
      9      ["dom.script_loader.experimental.navigation_cache", false],
     10    ],
     11  });
     12 
     13  await runJSCacheTests([
     14    // A small file shouldn't be saved to the disk.
     15    {
     16      title: "small file",
     17      items: [
     18        {
     19          file: "file_js_cache_small.js",
     20          events: [
     21            ev("load:source", "file_js_cache_small.js"),
     22            ev("evaluate:classic", "file_js_cache_small.js"),
     23            ev("diskcache:disabled", "file_js_cache_small.js"),
     24          ],
     25        },
     26        {
     27          file: "file_js_cache_small.js",
     28          events: [
     29            ev("load:source", "file_js_cache_small.js"),
     30            ev("evaluate:classic", "file_js_cache_small.js"),
     31            ev("diskcache:disabled", "file_js_cache_small.js"),
     32          ],
     33        },
     34        {
     35          file: "file_js_cache_small.js",
     36          events: [
     37            ev("load:source", "file_js_cache_small.js"),
     38            ev("evaluate:classic", "file_js_cache_small.js"),
     39            ev("diskcache:disabled", "file_js_cache_small.js"),
     40          ],
     41        },
     42        {
     43          file: "file_js_cache_small.js",
     44          events: [
     45            ev("load:source", "file_js_cache_small.js"),
     46            ev("evaluate:classic", "file_js_cache_small.js"),
     47            ev("diskcache:disabled", "file_js_cache_small.js"),
     48          ],
     49        },
     50      ],
     51    },
     52 
     53    // A large file should be saved to the disk on the 4th load, and should be
     54    // used on the 5th load.  Also the 5th load shouldn't overwrite the cache.
     55    {
     56      title: "large file",
     57      items: [
     58        {
     59          file: "file_js_cache_large.js",
     60          events: [
     61            ev("load:source", "file_js_cache_large.js"),
     62            ev("evaluate:classic", "file_js_cache_large.js"),
     63            ev("diskcache:disabled", "file_js_cache_large.js"),
     64          ],
     65        },
     66        {
     67          file: "file_js_cache_large.js",
     68          events: [
     69            ev("load:source", "file_js_cache_large.js"),
     70            ev("evaluate:classic", "file_js_cache_large.js"),
     71            ev("diskcache:disabled", "file_js_cache_large.js"),
     72          ],
     73        },
     74        {
     75          file: "file_js_cache_large.js",
     76          events: [
     77            ev("load:source", "file_js_cache_large.js"),
     78            ev("evaluate:classic", "file_js_cache_large.js"),
     79            ev("diskcache:disabled", "file_js_cache_large.js"),
     80          ],
     81        },
     82        {
     83          file: "file_js_cache_large.js",
     84          events: [
     85            ev("load:source", "file_js_cache_large.js"),
     86            ev("evaluate:classic", "file_js_cache_large.js"),
     87            ev("diskcache:register", "file_js_cache_large.js"),
     88            ev("diskcache:saved", "file_js_cache_large.js", false),
     89          ],
     90        },
     91        {
     92          file: "file_js_cache_large.js",
     93          events: [
     94            ev("load:diskcache", "file_js_cache_large.js"),
     95            ev("evaluate:classic", "file_js_cache_large.js"),
     96            ev("diskcache:disabled", "file_js_cache_large.js"),
     97          ],
     98        },
     99        {
    100          file: "file_js_cache_large.js",
    101          events: [
    102            ev("load:diskcache", "file_js_cache_large.js"),
    103            ev("evaluate:classic", "file_js_cache_large.js"),
    104            ev("diskcache:disabled", "file_js_cache_large.js"),
    105          ],
    106        },
    107      ],
    108    },
    109 
    110    // A file with compile error shouldn't be saved to the disk.
    111    {
    112      title: "syntax error",
    113      items: [
    114        {
    115          file: "file_js_cache_large_syntax_error.js",
    116          events: [
    117            ev("load:source", "file_js_cache_large_syntax_error.js"),
    118            ev("diskcache:disabled", "file_js_cache_large_syntax_error.js"),
    119          ],
    120        },
    121        {
    122          file: "file_js_cache_large_syntax_error.js",
    123          events: [
    124            ev("load:source", "file_js_cache_large_syntax_error.js"),
    125            ev("diskcache:disabled", "file_js_cache_large_syntax_error.js"),
    126          ],
    127        },
    128        {
    129          file: "file_js_cache_large_syntax_error.js",
    130          events: [
    131            ev("load:source", "file_js_cache_large_syntax_error.js"),
    132            ev("diskcache:disabled", "file_js_cache_large_syntax_error.js"),
    133          ],
    134        },
    135        {
    136          file: "file_js_cache_large_syntax_error.js",
    137          events: [
    138            ev("load:source", "file_js_cache_large_syntax_error.js"),
    139            ev("diskcache:disabled", "file_js_cache_large_syntax_error.js"),
    140          ],
    141        },
    142      ],
    143    },
    144  ]);
    145 
    146  await SpecialPowers.popPrefEnv();
    147 });
    148 
    149 add_task(async function testMemoryCache() {
    150  if (!AppConstants.NIGHTLY_BUILD) {
    151    todo(false, "navigation cache is not yet enabled on non-nightly");
    152    return;
    153  }
    154 
    155  await SpecialPowers.pushPrefEnv({
    156    set: [
    157      ["dom.expose_test_interfaces", true],
    158      ["dom.script_loader.bytecode_cache.enabled", true],
    159      ["dom.script_loader.bytecode_cache.strategy", 0],
    160      ["dom.script_loader.experimental.navigation_cache", true],
    161    ],
    162  });
    163 
    164  // If in-memory cache is enabled, the disk cache is handled by the
    165  // SharedScriptCache, and following differences happen:
    166  //  * diskcache:disabled and diskcache:register are not notified for
    167  //    each script
    168  //  * diskcache:noschedule is notified without associated script
    169  //    if there's no script to be saved
    170 
    171  await runJSCacheTests([
    172    // A small file should be saved to the memory on the 1st load, and used on
    173    // the 2nd load.  But it shouldn't be saved to the disk cache.
    174    {
    175      title: "small file",
    176      items: [
    177        {
    178          file: "file_js_cache_small.js",
    179          events: [
    180            ev("load:source", "file_js_cache_small.js"),
    181            ev("memorycache:saved", "file_js_cache_small.js"),
    182            ev("evaluate:classic", "file_js_cache_small.js"),
    183            ev("diskcache:noschedule"),
    184          ],
    185        },
    186        {
    187          file: "file_js_cache_small.js",
    188          events: [
    189            ev("load:memorycache", "file_js_cache_small.js"),
    190            ev("evaluate:classic", "file_js_cache_small.js"),
    191            ev("diskcache:noschedule"),
    192          ],
    193        },
    194        {
    195          file: "file_js_cache_small.js",
    196          events: [
    197            ev("load:memorycache", "file_js_cache_small.js"),
    198            ev("evaluate:classic", "file_js_cache_small.js"),
    199            ev("diskcache:noschedule"),
    200          ],
    201        },
    202        {
    203          file: "file_js_cache_small.js",
    204          events: [
    205            ev("load:memorycache", "file_js_cache_small.js"),
    206            ev("evaluate:classic", "file_js_cache_small.js"),
    207            ev("diskcache:noschedule"),
    208          ],
    209        },
    210      ],
    211    },
    212 
    213    // A large file should be saved to the memory on the 1st load, and used on
    214    // the 2nd load.  Also it should be saved to the disk on the 4th load.
    215    // Also the 5th load shouldn't overwrite the cache.
    216    // Once the memory cache is purged, it should be populated from the disk
    217    // cache response.
    218    {
    219      title: "large file",
    220      items: [
    221        {
    222          file: "file_js_cache_large.js",
    223          events: [
    224            ev("load:source", "file_js_cache_large.js"),
    225            ev("memorycache:saved", "file_js_cache_large.js"),
    226            ev("evaluate:classic", "file_js_cache_large.js"),
    227            ev("diskcache:noschedule"),
    228          ],
    229        },
    230        {
    231          file: "file_js_cache_large.js",
    232          events: [
    233            ev("load:memorycache", "file_js_cache_large.js"),
    234            ev("evaluate:classic", "file_js_cache_large.js"),
    235            ev("diskcache:noschedule"),
    236          ],
    237        },
    238        {
    239          file: "file_js_cache_large.js",
    240          events: [
    241            ev("load:memorycache", "file_js_cache_large.js"),
    242            ev("evaluate:classic", "file_js_cache_large.js"),
    243            ev("diskcache:noschedule"),
    244          ],
    245        },
    246        {
    247          file: "file_js_cache_large.js",
    248          events: [
    249            ev("load:memorycache", "file_js_cache_large.js"),
    250            ev("evaluate:classic", "file_js_cache_large.js"),
    251            ev("diskcache:saved", "file_js_cache_large.js", false),
    252          ],
    253        },
    254        {
    255          file: "file_js_cache_large.js",
    256          events: [
    257            ev("load:memorycache", "file_js_cache_large.js"),
    258            ev("evaluate:classic", "file_js_cache_large.js"),
    259            ev("diskcache:noschedule"),
    260          ],
    261        },
    262        {
    263          file: "file_js_cache_large.js",
    264          events: [
    265            ev("load:memorycache", "file_js_cache_large.js"),
    266            ev("evaluate:classic", "file_js_cache_large.js"),
    267            ev("diskcache:noschedule"),
    268          ],
    269        },
    270 
    271        {
    272          clearMemory: true,
    273          file: "file_js_cache_large.js",
    274          events: [
    275            ev("load:diskcache", "file_js_cache_large.js"),
    276            ev("memorycache:saved", "file_js_cache_large.js"),
    277            ev("evaluate:classic", "file_js_cache_large.js"),
    278            ev("diskcache:noschedule"),
    279          ],
    280        },
    281        {
    282          file: "file_js_cache_large.js",
    283          events: [
    284            ev("load:memorycache", "file_js_cache_large.js"),
    285            ev("evaluate:classic", "file_js_cache_large.js"),
    286            ev("diskcache:noschedule"),
    287          ],
    288        },
    289      ],
    290    },
    291 
    292    // A file with compile error shouldn't be saved to any cache.
    293    {
    294      title: "syntax error",
    295      items: [
    296        {
    297          file: "file_js_cache_large_syntax_error.js",
    298          events: [
    299            ev("load:source", "file_js_cache_large_syntax_error.js"),
    300            ev("diskcache:noschedule"),
    301          ],
    302        },
    303        {
    304          file: "file_js_cache_large_syntax_error.js",
    305          events: [
    306            ev("load:source", "file_js_cache_large_syntax_error.js"),
    307            ev("diskcache:noschedule"),
    308          ],
    309        },
    310        {
    311          file: "file_js_cache_large_syntax_error.js",
    312          events: [
    313            ev("load:source", "file_js_cache_large_syntax_error.js"),
    314            ev("diskcache:noschedule"),
    315          ],
    316        },
    317        {
    318          file: "file_js_cache_large_syntax_error.js",
    319          events: [
    320            ev("load:source", "file_js_cache_large_syntax_error.js"),
    321            ev("diskcache:noschedule"),
    322          ],
    323        },
    324      ],
    325    },
    326  ]);
    327 
    328  await SpecialPowers.popPrefEnv();
    329 });