Add test to the MapParser class in OTA_analyzer.

Add unit test to the MapParser class in map_parser.js. Please refer to
this CL for the original class definition:

https://android-review.googlesource.com/c/platform/development/+/1760909

Test: npm run test:unit
Change-Id: I2d640e9c5e27c0a012e32b4be09348034b67b235
diff --git a/tools/ota_analysis/jest.config.js b/tools/ota_analysis/jest.config.js
index 4dbaae6..c23e006 100644
--- a/tools/ota_analysis/jest.config.js
+++ b/tools/ota_analysis/jest.config.js
@@ -1,6 +1,14 @@
+const defaults = require('jest-config')
+
 module.exports = {
   preset: '@vue/cli-plugin-unit-jest',
   transform: {
     '^.+\\.vue$': 'vue-jest'
+  },
+  globals: {
+    ...defaults.globals,
+    crypto: require('crypto'),
+    TextEncoder: require('util').TextEncoder,
+    TextDecoder: require('util').TextDecoder,
   }
-}
+}
\ No newline at end of file
diff --git a/tools/ota_analysis/src/__tests__/map_parser.test.js b/tools/ota_analysis/src/__tests__/map_parser.test.js
new file mode 100644
index 0000000..6d5243f
--- /dev/null
+++ b/tools/ota_analysis/src/__tests__/map_parser.test.js
@@ -0,0 +1,63 @@
+import * as zip from '@zip.js/zip.js/dist/zip-full.min.js'
+import { MapParser } from '@/services/map_parser.js'
+
+var targetFile = new Blob()
+var mapParser
+// Please refer to system_test.map for more details.
+const systemMap = [
+  '//system/apex/com.android.test1.apex',
+  '//system/apex/com.android.test2.apex',
+  '//system/apex/com.android.test2.apex',
+  '//system/apex/com.android.test2.apex',
+  '//system/apex/com.android.test3.apk',
+  '//system/apex/com.android.test1.apex',
+  '//system/apex/com.android.test1.apex',
+  '//system/apex/com.android.test1.apex',
+  '//system/apex/com.android.test1.apex',
+  'unknown',
+  '//init.environ.rc'
+]
+
+/**
+ * Generate a virtual Android build which only contains a .map file
+ */
+beforeAll(async () => {
+  // web worker is not supported by zip.js, turn it off
+  zip.configure({
+    useWebWorkers: false,
+  })
+  // Use system_test.map as a virtual map file
+  const fs = require("fs")
+  const path = require("path")
+  const file = path.join(__dirname, "./", "system_test.map")
+  const text = fs.readFileSync(file, 'utf-8', (err, data) => data)
+  const blobWriter = new zip.BlobWriter("application/zip")
+  const writer = new zip.ZipWriter(blobWriter)
+  await writer.add("IMAGES/system_test.map", new zip.TextReader(text))
+  await writer.close()
+  targetFile = blobWriter.getData()
+  mapParser = new MapParser(targetFile)
+  await mapParser.init()
+})
+
+test('Initialize a map parser instance.', () => {
+  expect(mapParser.mapFiles.keys().next().value).toEqual('system_test')
+})
+
+test('Establish a map of system file.', async () => {
+  await mapParser.add('system_test', 11)
+  expect(mapParser.maps.get('system_test')).toEqual(systemMap)
+})
+
+test('Query the map of system file.', async () => {
+  await mapParser.add('system_test', 11)
+  var queryExtents = []
+  for (let i = 0; i < 11; i++)
+    queryExtents.push(new Object({
+      startBlock: i,
+      // The number of blocks does not matter, because we only query the
+      // starting block.
+      numBlocks: 0
+    }))
+  expect(mapParser.query('system_test', queryExtents)).toEqual(systemMap)
+})
\ No newline at end of file
diff --git a/tools/ota_analysis/src/__tests__/system_test.map b/tools/ota_analysis/src/__tests__/system_test.map
new file mode 100644
index 0000000..9b61b41
--- /dev/null
+++ b/tools/ota_analysis/src/__tests__/system_test.map
@@ -0,0 +1,4 @@
+//init.environ.rc 10
+//system/apex/com.android.test1.apex 5-6 0 0 7-8
+//system/apex/com.android.test2.apex 1-3
+//system/apex/com.android.test3.apk 4
\ No newline at end of file